提升布局性能____Re-using Layouts with <include/>
2024-09-01 01:28:56
可以再一个布局中通过“include”和“merge”元素进行复用其他的布局元素。
比如如下一个布局:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:background="@color/titlebar_bg"> <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/gafricalogo" />
</FrameLayout>
这是一个可复用的布局文件,倘若有以下的布局文件:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background="@color/app_bg"
android:gravity="center_horizontal"> <include
layout="@layout/titlebar"/> <TextView
android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:text="@string/hello"
android:padding="10dp" /> ...
</LinearLayout>
则包含了被复用的文件。
当然,如果在包含者当中,需要调整被包含者的属性,也可以:
<include android:id=”@+id/news_title”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
layout=”@layout/title”/>
这样就重新调整了被包含者的属性。
android中海油另一个“merge”标签,看了官方文档后,我个人理解是这样:
假使主布局中的根元素是线性布局,通过include包含了一个子布局,该子布局的根元素仍然是线性布局,那么包含后就与主布局的线性元素重复了,所以可以通过“merge”来解决,
<merge
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/add"/>
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/delete"/>
</merge>
最新文章
- input输入
- SSTable 介绍(二)
- NSArray Sort 排序
- Java异步IO/NIO
- tree 查询出数据遍历tree
- 当在Win8下安装msi类型的文件出现errorcode 2503的解决方法
- [翻译][MVC 5 + EF 6] 3:排序、过滤、分页
- ASP.NET 后台不识别ASPX中的控件
- 使用Gird++打印出现“Retrieving the COM class factory for component with CLSID”的解决办法
- Java 之Integer相等比较
- mac home/end/pageup/pageDown
- Java Arrays 源码 笔记
- transform做2d和3d变形(css动画一)
- linux的简单命令 网络配置
- BZOJ1854: [Scoi2010]游戏 二分图
- Java集合类的底层实现探索
- 转Centos7.0进入单用户模式修改root密码
- 算法相关——Java排序算法之希尔排序(五)
- pymongo
- B - Avoiding a disaster
热门文章
- 微信小程序把玩(三十八)获取设备信息 API
- MVC4升级MVC5导致原项目出错的解决方法
- Window文件目录遍历 和 WIN32_FIND_DATA 结构(非常详细的中文注释)
- Elasticsearch教程(一)简介与安装
- C++数组指针、指针数组、函数指针的核心概念
- qobject_cast<;QPushButton*>;(sender()) 简化信号与槽的编写(sender()取得发信号的对象后,就取得了它的全部信息,为所欲为)
- Spectre小计
- GO方法与接口
- kubernetes使用http rest api访问集群之使用postman工具访问 apiserver
- centos安装最新版MySQL 8.0教程