Layout Resource官方教程(3)在layout中用include嵌入其它layout
简介
<include>
Includes a layout file into this layout.
类似 #include ,把layout展开在include处
attributes:
layout | Layout resource. Required. 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的更多相关文章
- Layout Resource官方教程(2)用ViewStub引用的嵌入的layout可推迟加载
Loading Views On Demand THIS LESSON TEACHES YOU TO Define a ViewStub Load the ViewStub Layout YOU SH ...
- Layout Resource官方教程(1)简介
Layout Resource SEE ALSO Layouts A layout resource defines the architecture for the UI in an Activit ...
- Layout Resource官方教程(4)<include>与<merge>
Re-using Layouts with <include/> THIS LESSON TEACHES YOU TO Create a Re-usable Layout Use the ...
- 自定义View(7)官方教程:自定义View(含onMeasure),自定义一个Layout(混合组件),重写一个现有组件
Custom Components In this document The Basic Approach Fully Customized Components Compound Controls ...
- ActionBar官方教程(7)自定义操作项的view,如何得到它及处理它的事件
Adding an Action View An action view is a widget that appears in the action bar as a substitute for ...
- Python-第三方库requests详解(附requests中文官方教程)
转自http://blog.csdn.net/cyjs1988/article/details/73294774 Python+requests中文官方教程: http://www.python-re ...
- Toasts官方教程
Toasts IN THIS DOCUMENT The Basics Positioning your Toast Creating a Custom Toast View 在其它线程中启动Toast ...
- SwiftUI 官方教程(八)
8. 动态生成预览 接下来,我们会在 LandmarkList_Previews 中添加代码以在不同的设备尺寸上渲染列表.默认情况下,预览会以当前的 scheme 中设备的大小进行渲染.我们可以通过调 ...
- Ceisum官方教程2 -- 项目实例(workshop)
原文地址:https://cesiumjs.org/tutorials/Cesium-Workshop/ 概述 我们很高兴欢迎你加入Cesium社区!为了让你能基于Cesium开发自己的3d 地图项目 ...
随机推荐
- [记录 ]升级IOS 9 和 XCode 7 引起的问题
问题一: 升级xcode 7最低的系统配置要求 升级了ios9 后使用 xcode 6.1 已经不能用了,必须升级 xcode 7才行,原先的系统是OSX 10.10.1 版本.而xcode 7.0 ...
- springmvc学习(五)——处理模型数据
Spring MVC 提供了以下几种途径输出模型数据: ModelAndView: 处理方法返回值类型为 ModelAndView 时, 方法体即可通过该对象添加模型数据Map 及 Model: 入参 ...
- How to debug Custom Action DLL
在MSI工程中,经常会遇到这样的情况: MSI 工程需要调用DLL(C++)中的一个函数实现某些特殊或者复杂的功能,通常的做法是在Custom Action 中调用该DLL . 那么在安装过程中,该C ...
- DataGridView绘制序号
1.找到RowPostPaint事件 2.写入事件 /// <summary> /// 绘制序号 /// </summary> private void dgvStatemen ...
- ado.net中的几个对象
Connection:用于连接数据源 Command:对数据源执行命令 DataReader:在只读和只写的连接模式下从数据源读取数据. DataAdpter:从数据源读取数据并使用所读取的数据填充数 ...
- C#实现登录窗口(不用隐藏)
C#登录窗口的实现,特点就是不用隐藏,感兴趣的朋友不要错过 (1).在程序入口处,打开登录窗口 复制代码代码如下: static void Main() { Application.EnableV ...
- Linux启用MySQL的InnoDB引擎
前几天公司的一个项目组的同事反应说公司内部的一台Linux服务器上的MySQL没有InnoDB这个引擎,我当时想应该不可能啊,MySQL默认应该 就已经安装了这个引擎的吧,于是上服务器去看了看,发现还 ...
- Rsync+Inotify-tools实现数据实时同步
inotify是一种强大的,细粒度的,异步文件系统时间监控机制,它可以替代crond实现与rsync的触发式文件同步,从而监控文件系统中添加,删除,修改,移动等细粒事件,从LINUX 2.6.13起, ...
- ubuntu u盘安装
参考博客:http://www.bjwilly.com/archives/325.html 1.下载光盘映像 目前可选12.04LTS(长期支持版本) http://www.ubuntu.org.cn ...
- python中 “与,或,异或”
在python编程语言里面: 按位的运算,都按位的运算,都是把参加运算的数的二进制形式进行运算. 1.与运算:A与B值均为1时,A.B与的运算结果才为1,否则为0 (运算符:&) 2.或运算: ...