[1]在activity布局中定义fragment

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.itheima.fragment.Fragment1"
android:id="@+id/list"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.itheima.fragment.Fragment2"
android:id="@+id/viewer"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>

[2]声明fragment

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; //定义一个Fragment
public class Fragment1 extends Fragment { //当用户第一次画ui的时候调用 要显示Fragment自己的内容 setContentView(R.layout.activity_main);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//[1]通过打气筒把一个布局转换成view对象
View view = inflater.inflate(R.layout.fragment1, null); return view;
}
}

[3]name属性 要指定我们自己定义的fragment

最新文章

  1. 【ORACLE】记录通过执行Oracle的执行计划查询SQL脚本中的效率问题
  2. hdc cdc
  3. Java基础知识:序列化和反序列化
  4. 【转】eclipse中egit插件使用
  5. C#程序员整理的Unity 3D笔记(十):Unity3D的位移、旋转的3D数学模型
  6. 查看Linux下网卡状态或 是否连接(转)
  7. 基于JDK6的JAX-WX为客户端提供XML与JSON格式数据服务,以及客户端采用AXIS调用案例
  8. Java常见快捷键
  9. Collections.sort()的分析
  10. Flume-ng高可用集群负载安装与配置
  11. zabbix_agentd重装后启动时IPC和共享内存段问题
  12. python, generator.next()和send()
  13. TextView设置文字包含中英文时自动换行问题的终极解决方案
  14. [JS] ECMAScript 6 - String, Number, Function : compare with c#
  15. .Net下EF的简单实现
  16. E - 食物链
  17. OpenGL学习--01--打开一个窗口
  18. 理解 Linux 的平均负载和性能监控
  19. aarch64_m1
  20. CodeForces 811B Vladik and Complicated Book

热门文章

  1. mysql聚集索引的优缺点
  2. js的作用域
  3. ACM题目————网格动物
  4. ACM题目————STL练习之 懒省事的小明(优先队列)
  5. js笔记---封装一般运动
  6. poj2269 Friends
  7. Ahui Writes Word
  8. Selenium WebDriver + Python 环境配置
  9. VS2010常用快捷键
  10. WebForm上传文件FileUpload