可以再一个布局中通过“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>

最新文章

  1. input输入
  2. SSTable 介绍(二)
  3. NSArray Sort 排序
  4. Java异步IO/NIO
  5. tree 查询出数据遍历tree
  6. 当在Win8下安装msi类型的文件出现errorcode 2503的解决方法
  7. [翻译][MVC 5 + EF 6] 3:排序、过滤、分页
  8. ASP.NET 后台不识别ASPX中的控件
  9. 使用Gird++打印出现“Retrieving the COM class factory for component with CLSID”的解决办法
  10. Java 之Integer相等比较
  11. mac home/end/pageup/pageDown
  12. Java Arrays 源码 笔记
  13. transform做2d和3d变形(css动画一)
  14. linux的简单命令 网络配置
  15. BZOJ1854: [Scoi2010]游戏 二分图
  16. Java集合类的底层实现探索
  17. 转Centos7.0进入单用户模式修改root密码
  18. 算法相关——Java排序算法之希尔排序(五)
  19. pymongo
  20. B - Avoiding a disaster

热门文章

  1. 微信小程序把玩(三十八)获取设备信息 API
  2. MVC4升级MVC5导致原项目出错的解决方法
  3. Window文件目录遍历 和 WIN32_FIND_DATA 结构(非常详细的中文注释)
  4. Elasticsearch教程(一)简介与安装
  5. C++数组指针、指针数组、函数指针的核心概念
  6. qobject_cast&lt;QPushButton*&gt;(sender()) 简化信号与槽的编写(sender()取得发信号的对象后,就取得了它的全部信息,为所欲为)
  7. Spectre小计
  8. GO方法与接口
  9. kubernetes使用http rest api访问集群之使用postman工具访问 apiserver
  10. centos安装最新版MySQL 8.0教程