最后是Activity的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<fragment
android:id="@+id/left_fragment"
android:name="com.sunflower.LeftFragment"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="3" />
<fragment
android:id="@+id/right_fragment"
android:name="com.sunflower.RightFragment"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
在Activity中的布局文件中加入Fragment标签,其中android:name属性对应的就是自定义Fragment类的全名,系统会根据这个调用指定的Fragment的onCreateView()方法来得到这个Fragment的布局,然后加入Activity中. onCreateView()方法中的Container参数就是这时候传递过去的。
看看显示结果:
打开程序时生命周期显示:
按返回键时生命周期显示:












