android布局优化-merge
来源:互联网 发布:游戏礼包领取软件 编辑:程序博客网 时间:2024/06/05 15:15
前言:merge主要是进行UI布局的优化的,删除多余的层级,优化UI。<merge/>多用于替换frameLayout或者当一个布局包含另一个布局的时候,<merge/>标签用于消除师徒层次结构中多余的视图组。例如你的朱布局文件是垂直的,此时如果你引入一个垂直布局的<include>.这时如果include布局使用的LinearLayout就没意义了,使用的话反而减慢你的UI表现。这时可以使用<merge/>标签优化。<merge>标签也就是排除一个布局插入另一个布局产生的多余的viewgroup.
布局的效果<这里注意是frameLayout的效果>,为什么用在这里呢,因为android有一个默认的FrameLayout的布局
效果
1.用法
<merge 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" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="我是button3" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="我是button2" /></merge>
布局的效果<这里注意是frameLayout的效果>,为什么用在这里呢,因为android有一个默认的FrameLayout的布局
2.当把有<merge>标签的布局放在<include>中的时候,就会忽视<merge>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <include layout="@layout/fragment_main" /></LinearLayout>
效果
3.<merge>标签的限制
小白: <merge />标签有什么限制没?
小黑: <merge />只能作为XML布局的根标签使用。当Inflate以<merge />开头的布局文件时,必须指定一个父ViewGroup,并且必须设定attachToRoot为true。
点击打开原文地址
0 0
- Android merge布局优化
- android布局优化-merge
- Android、布局优化、include、merge、
- android-布局优化:merge+include
- Android-布局优化(include , merge , ViewStub)
- Android 布局优化之include、merge、ViewStub
- Android 布局优化之include与merge
- Android布局优化之merge标签
- android 布局优化标签<include/>、<merge />、<ViewStub />
- android Merge的使用(布局的优化)
- Android布局优化 merge标签使用
- Android之布局优化include、merge 、ViewStub
- Android 布局优化merge标签的使用
- android 布局优化(二),merge标签
- Android布局优化之include、ViewStub、merge
- Android 布局优化(merge使用)
- Android布局优化之merge(二)
- Android使用include/merge/ViewStub优化布局
- PAT-B 1018. 锤子剪刀布 (20)
- 17-02-08
- Training5 指针和链表训练
- java多线程复习
- 解决你的乱码难题(Qt转码与char和utf8的互转)
- android布局优化-merge
- Tomcat源码分析(二)------ 一次完整请求的里里外外
- Vector数组排序与Vector相等
- PAT甲级C语言.1005. 继续(3n+1)猜想
- 算法训练 区间k大数查询
- 人事管理系统实现(八)
- 给老板汇报技术规划的一些要点
- TCP socket连接错误: socket operation on non-socket
- 用户贷款风险预测之Top10初体验