activity_main.xml подобно этомуAndroid Fragment себя странно
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button_one_activity_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="First Button"
/>
<fragment
android:name="fragments.FirstFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/first_fragment" />
<Button
android:id="@+id/button_two_activity_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Second Button"
/>
</LinearLayout>
Основной класс активности, как это
package com.example.testfragmentshoneycomb;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
first_fragment.xml подобно этому
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/grey" >"
<TextView
android:id="@+id/text_view_one_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text View one" />
<TextView
android:id="@+id/text_view_two_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text View two" />
<TextView
android:id="@+id/text_view_three_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text View three" />
</LinearLayout>
класса FirstFragment как это
package fragments;
import com.example.testfragmentshoneycomb.R;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class FirstFragment extends Fragment{
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.first_fragment, container, false);
return view;
}
}
В нем отображается только первая кнопка и ничего больше на экране. Если я удалю первую кнопку из Activity_main.xml, она отобразит фрагмент, но не отобразит вторую кнопку.
Min SDK версии 11 и построить цель андроида 4,1
Спасибо большое – Atinder