Android布局优化 之 <merge>标签使用详解
来源:互联网 发布:淘宝争议处理规范 编辑:程序博客网 时间:2024/06/05 08:29
1.为什么要使用<merge>
为了避免嵌套过多无用布局,嵌套的布局会让View树的高度变得越来越高,应该尽量减少布局的层级来优化布局。
2.什么情况下使用<merge>
1.如果本打算用FrameLayout作为界面的根布局时,要用<merge>标签作为根节点,因为View树的ContentView本身就是个FrameLayout,如图:
2.如果打算用RelateLayout或Linearlayout作为界面根布局时,界面中某些可复用的或逻辑独立的布局用<include>导入,<include>导入的布局可以考虑用<merge>作为根节点。现在有个问题:<merge>根节点内的控件怎么布局呢?
<merge>根节点内的控件布局取决于<include>这个布局的父布局是哪个布局:
merge_in_layout.xml
<?xml version="1.0" encoding="utf-8"?><merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_gravity="center_horizontal" android:text="第一个标签" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_gravity="center_horizontal" android:text="第二个标签" /></merge>
父布局是RelateLayout时:
activity_merge_in_relate_layout.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.android.merge.MergeInRelateLayoutActivity"> <include layout="@layout/merge_in_layout"/></RelativeLayout>
<merge>标签内的控件就按照相对布局排列,如图:
父布局是LinearLayout时:
activity_merge_in_linear_layout.xml
<?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"> <include layout="@layout/merge_in_layout" /></LinearLayout>
<merge>标签内的控件就按照线性布局排列,如图:
阅读全文
1 0
- Android布局优化 之 <merge>标签使用详解
- android优化之布局优化-Merge标签的使用
- Android布局优化之<merge>与<ViewStub>标签使用
- android布局优化之<merge>标签的使用
- Android布局优化之merge标签
- Android布局优化 merge标签使用
- Android 布局优化merge标签的使用
- 使用merge标签优化布局
- 性能优化之布局优化篇二 使用<merge>标签
- Android 性能优化 四 布局优化merge标签的使用
- android 布局优化标签<include/>、<merge />、<ViewStub />
- android 布局优化(二),merge标签
- Android 布局优化 include,merge,viewstub标签
- 布局优化---merge标签的使用
- Android布局优化之include、merge、ViewStub的使用
- Android layout之优化:使用include和merge 标签
- Android layout之优化:使用include和merge 标签
- Android UI优化之merge标签的使用
- 前台与后台数据交互
- IBM3650服务器启动报错/dev/VolGroup00/LogVo100: UNEXPECTED INCONSISTENCY :RUN fsck MANUALLY.
- Spring MVC 详细示例教程
- 获取控制台输出的信息,发送给前台页面
- mysql连接及数据库操作
- Android布局优化 之 <merge>标签使用详解
- RocketMQ命令整理
- 使用卷积神经网络进行图片分类 1
- mac Nginx+Nodejs配置
- angular学习(一)
- Android快速开发系列 10个常用工具类
- Replace Delegation with Inheritance(以委托取代继承)
- URL美化与链接
- 成长感悟吧?