Fragment
来源:互联网 发布:hbase不直接删除数据 编辑:程序博客网 时间:2024/05/01 15:11
<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: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>
@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: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();
}
}
1 0
- Fragment
- Fragment
- fragment
- Fragment
- Fragment
- Fragment
- Fragment
- fragment
- fragment
- Fragment
- Fragment
- fragment
- Fragment
- Fragment
- Fragment
- Fragment
- Fragment
- fragment
- c#之datagridview格式
- zoj3228AC自动机
- CSS初探
- VE设计#6 表现层query界面
- cocos2dx 3.3 + lua 学习笔记(03)--- 触摸事件、定时器、进度条
- Fragment
- Tesseract-Oct的使用及语言库的训练
- HDU 1521 排列组合(指数型母函数)
- 网络配置
- c#-随机数2
- Windows + IDEA + SBT 打造Spark源码阅读环境
- Thinking in Java:容器深入研究
- CentOS 6.0 启动时出现fstab错误时的修复
- java基础知识总结(二)