活动里面添加一个碎片
2016-09-19 18:06
183 查看
fragment的布局文件fragment_demo.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
android:paddingBottom="0dp"
android:paddingLeft="@dimen/ijk_horizontal_margin"
android:paddingRight="@dimen/ijk_horizontal_margin"
android:paddingTop="0dp">
<EditText
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/play_url"/>
</LinearLayout>
Activity里面的布局文件
<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"
tools:context=".activities.FileExplorerActivity">
<include layout="@layout/widget_toolbar" />
<FrameLayout
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
把碎片添加到活动中去:
private void loadFragment() {
Log.d(TAG, "load DemoFragment");
Fragment newFragment = (Fragment)DemoFragment.newInstance();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
//把fragment的布局贴到App_Activity的frameLayout控件上
transaction.replace(R.id.body, newFragment);
transaction.commit();
}
这么简单就搞定。
<?xml version="1.0" encoding="utf-8"?>
<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"
android:paddingBottom="0dp"
android:paddingLeft="@dimen/ijk_horizontal_margin"
android:paddingRight="@dimen/ijk_horizontal_margin"
android:paddingTop="0dp">
<EditText
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/play_url"/>
</LinearLayout>
Activity里面的布局文件
<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"
tools:context=".activities.FileExplorerActivity">
<include layout="@layout/widget_toolbar" />
<FrameLayout
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
把碎片添加到活动中去:
private void loadFragment() {
Log.d(TAG, "load DemoFragment");
Fragment newFragment = (Fragment)DemoFragment.newInstance();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
//把fragment的布局贴到App_Activity的frameLayout控件上
transaction.replace(R.id.body, newFragment);
transaction.commit();
}
这么简单就搞定。
相关文章推荐
- 论我国24字核心价值观及其世界意义
- RelativeLayout布局用到的主要属性
- java基础:抽象类(09.27)
- Android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed
- 9.19练习
- XHR
- hadoop基础----hadoop实战(五)-----myeclipse开发MapReduce---WordCount例子---解析MapReduce的写法
- Maven搭建SpringMVC+Mybatis项目详解【转】
- hadoop基础----hadoop实战(五)-----myeclipse开发MapReduce---WordCount例子---解析MapReduce的写法
- 网站每日PV/IP统计/总带宽/URL统计脚本分享(依据网站访问日志)
- 邮箱正则校验
- iOS 无效的版本,提交成功,不出现版本号
- xfs_repair 时间花费与数据量关系
- ==与.equals方法的比较区别
- javascript高级程序设计——笔记
- table在网页中的居中显示
- 简述配置文件ini及其操作函数GetPrivateProfileString等
- Kafka技术带你玩转大数据!
- 最大公约数(最小公倍数)&回文串组数统计
- MFC中屏幕刷新闪烁问题解决方法总结