如何用fragment
来源:互联网 发布:c语言英语怎么说 编辑:程序博客网 时间:2024/05/29 04:01
fragment 个人认为就是本来可以用一个ACTIVITY来实现的页面,当然这个页面分为N个功能区域,如果全写在一个ACTIVITY,代码会很臃肿,而且有些区域的功能可能在另一个ACTIVITY也可以重复调用,写死在一个ACTIVITY就不大好了,Fragment就是把各个功能区域分开由不同的类去实现,在拼在一起。好处就是母ACTIVITY只关注各个区域的布局和如何和各个子FRAGMENT通讯,不用在写N多个逻辑了。
如下图所示 这种头身尾布局 简简单单,如果用fragment 我们如果不写死在一个ACTIVITY中的话,用FRAGMENT的话 我们需要写4个类来完成
主类是一个activity 然后就是 3个fragment fragment_header fragment_body fragment_footer
第1步,我们先定义好主ACTIVITY的布局先
代码如下
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RelatedLayout android:id="@+id/headerplaceholder" android:layout_width="match_parent" android:layout_height="wrap_content" > </RelatedLayout> <RelatedLayout android:id="@+id/bodyplaceholder" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > </RelatedLayout> <RelatedLayout android:id="@+id/footerplaceholder" android:layout_width="match_parent" android:layout_height="wrap_content" > </RelatedLayout> </LinearLayout>
未完待续
阅读全文
0 0
- 如何用fragment
- 如何用Fragment#setArguments(Bundle)传递变量到DialogFragment
- Fragment介绍和运用(如何用Fragment实现Tab切换的方法,)
- 开发中尽量用fragment代替activity来完成跳转,那么如何用fragment来替换activity来替换呢???
- 如何用2.0发信?
- 想知道socket如何用
- 如何用英语杀价?
- 如何用C画图
- 问如何用文件
- 如何用JSP编程
- 如何用PS切图
- ssl如何用
- 如何用FreeType写字
- 如何用计算机发财
- 如何用JAVA 对象?
- 如何用JDO查询
- 如何用tadodataset.append
- 如何用VS Debug
- 1 人身五行 初识
- 阿里云助力博客""装逼""成功
- js效果
- Android IBinder的linkToDeath介绍及情景模拟
- [JAVA学习笔记-84]关于死锁故障的反思
- 如何用fragment
- PHP_7.0_升级备注
- yahoo鉴黄模型测试
- PowerDesigner15.1创建模型及生成带注释sql
- hihoCoder 1051 : 补提交卡(贪心+枚举)
- 通过Flume拉取Kafka数据保存到HDFS
- Java注解
- [JAVA学习笔记-85]java的concurrent包的整体认识
- ServletContext与ApplicationContext