Android Fragment使用
??? 你可以像为View一样, 为fragment指定layout属性(sdk3.0以后).
????? 例子是一个有2个fragment的activity:<?xml version="1.0"?encoding="utf-8"?>
<LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????android:orientation="horizontal"
????android:layout_width="match_parent"
????android:layout_height="match_parent">
?????<fragment android:name="com.example.news.ArticleListFragment"
????????????android:id="@+id/list"
????????????android:layout_weight="1"
????????????android:layout_width="0dp"
????????????android:layout_height="match_parent"?/>
?????<fragment android:name="com.example.news.ArticleReaderFragment"
????????????android:id="@+id/viewer"
????????????android:layout_weight="2"
????????????android:layout_width="0dp"
????????????android:layout_height="match_parent"?/>
??</LinearLayout>
FragmentManager fragmentManager = getFragmentManager();?
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
????? add()的第一个参数是fragment要放入的ViewGroup, 由resource ID指定, 第二个参数是需要添加的fragment.一旦用FragmentTransaction做了改变,为了使改变生效,必须调用commit().ExampleFragment fragment =?new?ExampleFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);?
fragmentTransaction.commit();