简介

<include>Includes a layout file into this layout.

  1. 类似 #include ,把layout展开在include

attributes:

layout Layout resourceRequired. Reference to a layout resource.
android:id Resource ID. Overrides the ID given to the root view in the included layout.
android:layout_height Dimension or keyword. Overrides the height given to the root view in the included layout. Only effective if android:layout_width is also declared.
android:layout_width Dimension or keyword. Overrides the width given to the root view in the included layout. Only effective if android:layout_height is also declared.

  You can include any other layout attributes in the <include> that are supported by the root element in the included layout and they will override those defined in the root element.

  1. 注意,findViewById()都是父容器找子控件,被include layout里的控件要在都位于主layout中,所以要用 layout对应的view.findViewById()才能找到子layout中的控件。

Caution:

  If you want to override layout attributes using the <include> tag, you must override both android:layout_height and android:layout_width in order for other layout attributes to take effect.

  Another way to include a layout is to use ViewStub. It is a lightweight View that consumes no layout space until you explicitly inflate it, at which point, it includes a layout file defined by itsandroid:layout attribute. For more information about using ViewStub, read Loading Views On Demand.

示例:

主layout: frgmt_main.xml

  1.   <FrameLayout
  2. android:id="@android:id/tabcontent"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5.  
  6. <!-- tab1,用include可以引用别处的layout -->
  7. <include
  8. android:id="@+id/tab_weixin"
  9.  
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. layout="@layout/tab_weixin_layout" />

被include的layout :  tab_weixin_layout.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:id="@+id/tab_weixin_layout"
  6. android:orientation="vertical" >
  7. <LinearLayout
  8. android:id="@+id/tab_weixin_qq_friend"
  9. android:layout_width="match_parent"
  10. android:orientation="horizontal"
  11. android:layout_height="wrap_content" >
  12.  
  13. <ImageView
  14. android:id="@+id/iv_tab_weixin_qq_friend"
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:scaleType="centerInside"
  18. android:src="@drawable/tab_weixin_qq_scale" />
  19.  
  20. <TextView
  21. android:id="@+id/tv_tab_weixin_qq_friend"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:text="@string/find_qq_friends" />
  25.  
  26. </LinearLayout>
  27.  
  28. <ListView
  29. android:id="@+id/tab_weixin_list"
  30. android:layout_width="match_parent"
  31. android:layout_height="match_parent" >
  32. </ListView>
  33.  
  34. </LinearLayout>

Layout Resource官方教程(3)在layout中用include嵌入其它layout的更多相关文章

  1. Layout Resource官方教程(2)用ViewStub引用的嵌入的layout可推迟加载

    Loading Views On Demand THIS LESSON TEACHES YOU TO Define a ViewStub Load the ViewStub Layout YOU SH ...

  2. Layout Resource官方教程(1)简介

    Layout Resource SEE ALSO Layouts A layout resource defines the architecture for the UI in an Activit ...

  3. Layout Resource官方教程(4)<include>与<merge>

    Re-using Layouts with <include/> THIS LESSON TEACHES YOU TO Create a Re-usable Layout Use the ...

  4. 自定义View(7)官方教程:自定义View(含onMeasure),自定义一个Layout(混合组件),重写一个现有组件

    Custom Components In this document The Basic Approach Fully Customized Components Compound Controls ...

  5. ActionBar官方教程(7)自定义操作项的view,如何得到它及处理它的事件

    Adding an Action View An action view is a widget that appears in the action bar as a substitute for ...

  6. Python-第三方库requests详解(附requests中文官方教程)

    转自http://blog.csdn.net/cyjs1988/article/details/73294774 Python+requests中文官方教程: http://www.python-re ...

  7. Toasts官方教程

    Toasts IN THIS DOCUMENT The Basics Positioning your Toast Creating a Custom Toast View 在其它线程中启动Toast ...

  8. SwiftUI 官方教程(八)

    8. 动态生成预览 接下来,我们会在 LandmarkList_Previews 中添加代码以在不同的设备尺寸上渲染列表.默认情况下,预览会以当前的 scheme 中设备的大小进行渲染.我们可以通过调 ...

  9. Ceisum官方教程2 -- 项目实例(workshop)

    原文地址:https://cesiumjs.org/tutorials/Cesium-Workshop/ 概述 我们很高兴欢迎你加入Cesium社区!为了让你能基于Cesium开发自己的3d 地图项目 ...

随机推荐

  1. cocos2d-x实战 C++卷 学习笔记--第4章 使用菜单

    前言: 菜单中包含菜单项,菜单项类是 MenuItem ,每个菜单项都有三个基本状态:正常.选中和禁止. (MenuItem)菜单分类: (文本菜单)MenuItemLabel : MenuItemA ...

  2. 三【相关度 相似度查询与计算】相似度到大数据查找之Mysql 文章匹配的一些思路与提高查询速度

    记录下,在上2回的数据基础之上,附带一个互信息(MI,Mutual Information)可以计算词之间的相关度 标准互信息 MI(X,Y)=log2p(x,y)/p(x)p(y) 值越大于0 则趋 ...

  3. tomcat maxConnections和maxThreads区别

    maxConnections:与tomcat建立的最大socket连接数,默认10000(很多网上说200,实际上通过tomcat7.0.55源码查看可以知道是10000),AbstractEndpo ...

  4. 使用thinkPHP实现数据更新一例【原创】

    在上一篇文章中我们实现了数据的删除和批量删除,这一篇文章我们将实现数据的更新. 首先依然是预期效果图: 点击修改后进入modi.html页面,然后进行修改,如此处修改了真实姓名这一属性: 点击保存: ...

  5. mysql 常用命令搜集

    查看MYSQL数据库中所有用户及拥有权限 mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query F ...

  6. http数据包解析碰到gzip压缩格式的解压

    其中在做http数据包临控时碰到gzip压缩格式,在网友发布的一些技术文章基础上,经过一段时间的研究.调试,终于解析成功.现将核心代码公布于此,希望能够和大家一起共同学习交流.注:以下代码需要依赖zl ...

  7. Qt-获取网络接口信息的综合示例

    在前面的文章中介绍了与 获 取 本 机 网 络 信 息 相 关 的 类 常 用 的 有 4 个 , 分 别 是 : QHostAddress, QHostInfo, QNetworkInterface ...

  8. js 框架都有哪几种(转载)

    目前来看,js框架以及一些开发包和库类有如下几个,Dojo .Scriptaculous .Prototype .yui-ext .Jquery .Mochikit.mootools .moo.fxD ...

  9. Cassandra1.2文档学习(4)——分区器

    参考文档:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/architecture/a ...

  10. 两个不同于LR和jmeter的性能测试工具

    LR图形界面,更利于使用 jmeter采用java,也能够扩展 相对于上两款工具,下面两款性能测试工具都采用了异步IO模型,扩展性都更强速度也更快 gatling:基于scala,速度相比更快性能压力 ...