Fragment
2016-04-01 14:32
176 查看
<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"
android:orientation="vertical"
>
<RelativeLayout
android:layout_weight="1"
android:id="@+id/rl_1"
android:background="#ff0"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:id="@+id/rl_2"
android:background="#f00"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
</LinearLayout>
--------------------------------------------------------------------------------------------------------------------------------------
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 得到Fragment的管理者
FragmentManager supportFragmentManager = getSupportFragmentManager();
// 开启事务
FragmentTransaction beginTransaction = supportFragmentManager
.beginTransaction();
// 得到Fragment_1对象
Fragment_1 fragment_1 = new Fragment_1();
Fragment_2 fragment_2 = new Fragment_2();
// 添加Fragment_1到布局文件;参数一:被填充的布局,参数二:要填充的fragment
beginTransaction.add(R.id.rl_1, fragment_1);
beginTransaction.add(R.id.rl_2, fragment_2);
// 提交事务
beginTransaction.commit();
}
}
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<RelativeLayout
android:layout_weight="1"
android:id="@+id/rl_1"
android:background="#ff0"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:id="@+id/rl_2"
android:background="#f00"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
</LinearLayout>
--------------------------------------------------------------------------------------------------------------------------------------
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 得到Fragment的管理者
FragmentManager supportFragmentManager = getSupportFragmentManager();
// 开启事务
FragmentTransaction beginTransaction = supportFragmentManager
.beginTransaction();
// 得到Fragment_1对象
Fragment_1 fragment_1 = new Fragment_1();
Fragment_2 fragment_2 = new Fragment_2();
// 添加Fragment_1到布局文件;参数一:被填充的布局,参数二:要填充的fragment
beginTransaction.add(R.id.rl_1, fragment_1);
beginTransaction.add(R.id.rl_2, fragment_2);
// 提交事务
beginTransaction.commit();
}
}
相关文章推荐
- Iphone中的UIPopoverController
- OC代码小事项(一)
- Linux下通过ioctl系统调用来获取和设置网络信息
- Android 面试题总结(二)
- Hbase javaapi curd笔记
- 一个app跳转到另一个app的指定功能
- Java中IO流的序列化与反序列化
- 3.5趣味整数之勾股数
- c#中委托与多线程的实质
- 新Eclipse安装与配置
- CSS选择符详解
- 用jquery控制span显示几个字符
- 多继承且有内嵌对象时构造函数的调用顺序
- ext js中,Ext.Msg.confirm();的用法?
- webserver.c Simple HTTP server sample for sanos
- 求解二叉树的深度(递归和非递归)
- struts2请求过程源码分析
- windows 下配置java版xgboost
- 焦距
- 写给2016年开始步入开发工作的新宝宝们