activity布局中加载fragment
来源:互联网 发布:js实现圆圈动态显示 编辑:程序博客网 时间:2024/05/22 00:16
1.首先 创建fragment的类
package com.qianfeng.fragmentdemo;import android.app.Fragment;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;public class Fragment1 extends Fragment {/** * 当系统第一次绘制fragment的用户界面时回调的方法 * 返回当前fragment的根layout的view * 第一个参数 布局加载器对象 * 第二个参数 标示父容器 * 第三个参数 bundle 传递数据 *//** * 当系统第一次绘制fragment的用户界面是回调的方法 * 返回当前fragment的layout的view * * 第一个参数:布局加载器对象 * 第二个参数:表示父容器 * 第三个参数: bundle 传递数据的 */@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {//1参数 标示当前布局的资源ID 2参数 标示当前布局的父布局 3参数 是否需要追加父布局View view=inflater.inflate(R.layout.activity_fragment1, container, false);return view;}}
2,之后在activity的布局中调用Fragment 一般是 name=包名+类名
<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="horizontal"> <fragment android:name="com.qianfeng.fragmentdemo.Fragment1" android:id="@+id/fragment1" android:layout_height="match_parent" android:layout_width="0dp" android:layout_weight="1" /> <fragment android:name="com.qianfeng.fragmentdemo.Fragment2" android:id="@+id/fragment2" android:layout_height="match_parent" android:layout_width="0dp" android:layout_weight="1" /> <!-- android:name 指定activity中引入的fragment的 包名.类名 android:id="" 指定fragment的唯一标示 --></LinearLayout>
这样一个布局加载fragment就完成了
0 0
- activity布局中加载fragment
- Fragment中加载Activity
- Android让Fragment加载到Activity中
- Android让Fragment加载到Activity中
- Android让Fragment加载到Activity中
- Fragment——向Activity中动态加载Fragment
- Android如何让Fragment加载到Activity中
- fragment 中加载UI布局和使用findviewbyid
- Fragment里加载Activity界面
- android Fragment 懒加载布局
- 将Fragment加载到布局
- 不同的布局文件怎么加载到一个activity中
- Activity中布局资源layoutResId在setContentView加载过程分析
- Android中Activity和Fragment之间数据传递(例子中也有事务加载Fragment)
- 在activity中加载fragment的两个方式以及获取fragment中的控件的方式
- 关于Fragment中viewpager的子fragment不能加载布局的问题
- Activity中使用Fragment
- Fragment 中调用 activity
- 在消息对话框中显示文本之JOptionPane类
- [黑马程序员](第31天)高新技术之反射
- 编程艺术,经典!!!!!!!!!!
- android 的TextView与EditText
- 索引的设计原则
- activity布局中加载fragment
- motion的移植和配置
- SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
- 在 VS2013 中调用 ffmpeg 库函数
- 学习ubuntu之路(一) Ubuntu下,清屏等终端常用命令
- iterator、const_iterator和const iterator的区别
- Redis介绍和安装
- HTML基本知识点总结
- 做一点事情就想放松,然后就开始拖延,怎么克服?