简介

<include>Includes a layout file into this layout.

类似 #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.

注意,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

   <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"> <!-- tab1,用include可以引用别处的layout -->
<include
android:id="@+id/tab_weixin" android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/tab_weixin_layout" />

被include的layout :  tab_weixin_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:id="@+id/tab_weixin_layout"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/tab_weixin_qq_friend"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content" > <ImageView
android:id="@+id/iv_tab_weixin_qq_friend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="@drawable/tab_weixin_qq_scale" /> <TextView
android:id="@+id/tv_tab_weixin_qq_friend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/find_qq_friends" /> </LinearLayout> <ListView
android:id="@+id/tab_weixin_list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView> </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. python 笔记(一)

    1.Python优点 简单,优雅,明确 强大的模块第三方库 易移植 面向对角 可扩展 2.缺点 代码不能加密 执行速度慢 3.变量定义 第一个字母必须是字母表中的大小写,或下划线.不能以数字为开头. ...

  2. System.Web.Mvc.Html 命名空间小计(转)

    最近在看MVC框架,发现这个博文对初学者可能有帮助,故转之. 1,Html.Action    使用指定参数调用指定子操作方法并以 HTML 字符串形式返回结果. Html.Action() < ...

  3. ### 线性回归(Regression)

    linear regression logistic regression softmax regression #@author: gr #@date: 2014-01-21 #@email: fo ...

  4. ###STL学习--关联容器

    点击查看Evernote原文. #@author: gr #@date: 2014-08-23 #@email: forgerui@gmail.com STL中的关联容器. ###stl学习 |--迭 ...

  5. 第七篇、hitTest UITabbar中间突出按钮额外增加可点击区域

    简介: 以前UITabbar使用中间有一个凸起按钮时,常常就需要用到hitTest来处理可点击的范围. 示例代码: - (UIView *)hitTest:(CGPoint)point withEve ...

  6. jQuery 源码分析5: jQuery 基本静态方法(一)

    jQuery在初始化过程中会为自己扩展一些基本的静态方法和属性,以下是jQuery 1.11.3版本 239 ~ 564行间所扩展的静态属性和方法   jQuery.extend({ // 为每个jQ ...

  7. java集合 collection-list-vector

    import java.util.*; /* 枚举就是Vector特有的取出方式. 发现枚举和迭代器很像. 其实枚举和迭代是一样的. 因为枚举的名称以及方法的名称都过长. 所以被迭代器取代了. 枚举郁 ...

  8. UTF-8/UTF-16/UTF-32

    UTF-8/UTF-16/UTF-32 一.UTF-8/UTF-16/UTF-32三者的区别 二.BOM的检测与删除 1.用VIM去除<feff>,即 U+FEFF.注意:这是一个字符,而 ...

  9. 常用Linux/Unix/Mac Os命令

    常用Linux/Unix/Mac OS命令 参考: 1.50 Most Frequently Used UNIX / Linux Commands (With Examples)

  10. Move can only be called on an active agent that has been placed a Navmesh的解决办法

    这是虽然将场景物体添加了Nav Mesh,但是没有进行Bake(烘焙)导致的. 在网上查了 很多久,都没解决这个error,最后发现是因为在unity4.6以下版本中,Bake是Navigation下 ...