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