参考详细教程:
1.Android Fragment完全解析,关于碎片你所需知道的一切
http://blog.csdn.net/guolin_blog/article/details/8881711
注:
Fragment1 fragment1 = new Fragment1(); getFragmentManager().beginTransaction().replace(R.id.main_layout, fragment1).commit();
FragmentManager manager = getFragmentManager();//获取该Activity的FragmentManager FragmentTransaction transaction = manager.beginTransaction();//开启事务 transaction.replace(R.id.main_layout, fragment1);//用新的替换原有的Fragment,如果没有,则添加新的 transaction.commit();//提交事务每个Activity都有一个FragmentManager来管理它所包含的Fragment,FragmentManager可以通过getFragmentManager()方法访问。
FragmentManager通过beginTransaction()创建一个FragmentTransaction
FragmentTransaction用来添加、删除和替换Fragment
示例:
//新建一个Fragment Fragment1 fragment1 = new Fragment1(); //获取该Activity的FragmentManager FragmentManager manager = getFragmentManager(); //开启事务 FragmentTransaction transaction = manager.beginTransaction(); //添加Fragment,三个参数:容器ID,Fragment对象,标签(可省略) transaction.add(R.id.main_layout, fragment1, "fragment1"); //删除Fragment transaction.remove(fragment1); //替换Fragment transaction.replace(R.id.main_layout, fragment1, "fragment1"); //添加过渡动画 //transaction.setCustomAnimations(enter, exit); //添加到back栈中,用户按Back键可以返回上一个转换前的状态,strop此Fragment。如果不调用此方法,默认destroy transaction.addToBackStack("fragment1"); //提交事务 transaction.commit();
2.Android Fragment应用实战,使用碎片向ActivityGroup说再见
http://blog.csdn.net/guolin_blog/article/details/13171191
3.Android手机平板两不误,使用Fragment实现兼容手机和平板的程序
http://blog.csdn.net/guolin_blog/article/details/8744943
另附知识点:
android:layout_weight="1"
android:baselineAligned="false"
关于LinearLayout
http://www.cnblogs.com/moonz-wu/archive/2010/03/04/1677894.html