Android中文API-ViewStub
ViewStub控件是一个不可见,0尺寸得惰性控件。当ViewStub控件设置可见,或者调用inflate(),并运行完毕之后,ViewStub所指定的layout资源就会被载入。这个ViewStub就会被新载入的layout文件取代。
ViewStub也会从其父控件中移除。
因此ViewStub存在view
Hierarchy中的生存期为直到ViewStub运行了setVisable(int)或者inflate()方法。
在setVisable或者inflate方法运行完成。被载入的Layout文件伴随着ViewStub的属性设置一起被增加ViewStub的父控件中。
你能够定义或者重写被载入layout文件的id属性。
比如:
<ViewStub android:id="@+id/stub"
android:inflatedId="@+id/subTree"
android:layout="@layout/mySubTree"
android:layout_width="120dip"
android:layout_height="40dip" />
这个定义的ViewStub控件能够通过设定的id“stub”找到。在成功获取subTree制定的kayout之后,ViewStub就从其父控件中移除了,被载入的mySubTree,能够通过id“subTree”找到。从以上的代码属性设置来说,终于载入的Layout文件,会以宽120dp,高40dp展示。
通过下面方式,能够使ViewStub展示出其所代表的layout文件。
ViewStub stub = (ViewStub) findViewById(R.id.stub);
View inflated = stub.inflate();
当inflate()运行完毕,Viewstub就被替换掉了,inflate返回的View就是mySubTree这个布局文件的View。所以就不须要运行额外的findById了。
值得注意的是:ViewStub在Api1的时候就已经提供了,可是在api16的时候,添加了一个方法:
public void setLayoutInflater (LayoutInflater inflater)
这种方法攻克了,不能指定LayoutInflater 的问题,这涉及了Context的使用。
假设你在低于Api16的开发中,遇到找到不你载入View 的 id的情况,那多数情况是。Context出了问题。在低于api16的情况下,解决方案有两种:
(1)自己定义ViewStub
(2)在V7包中。使用ViewStubCompat类。
作者有话说:假设你须要或者Android中文API。请扫一扫以下的二维码,您的关注。就是我的动力。
Android中文API-ViewStub的更多相关文章
- Android 中文 API (40) —— RatingBar
Android 中文 API (40) —— RatingBar 前言 本章内容是 android.widget.RatingBar,译为"评分条",版本为Android 2.2 ...
- Android 中文API (70) —— BluetoothDevice[蓝牙]
前言 本章内容是 android.bluetooth.BluetoothDevice,为Android蓝牙部分的章节翻译.蓝牙设备类,代表了蓝牙通讯国足中的远端设备.版本为 Android 2.3 ...
- Android 中文API (69) —— BluetoothAdapter[蓝牙]
前言 本章内容是 android.bluetooth.BluetoothAdapter,为Android蓝牙部分的章节翻译.本地蓝牙设备的适配类,所有的蓝牙操作都要通过该类完成.版本为 Androi ...
- Android 中文API (68) —— BluetoothClass.Service
前言 本章内容是 android.bluetooth.BluetoothClass.Service,为Android蓝牙部分的章节翻译,版本为 Android 2.3 r1,翻译来自中山大学的&q ...
- Android 中文API (67) —— BluetoothClass.Device.Major
前言 本章内容是android.bluetooth.BluetoothClass.Device.Major,为Android蓝牙部分的章节翻译,版本为Android 2.3 r1,翻译来自中山大学 ...
- Android 中文API (66) —— BluetoothClass.Device
前言 本章内容是android.bluetooth.BluetoothClass.Device,为Android蓝牙部分的章节翻译,版本为Android 2.3 r1,翻译来自中山大学的" ...
- Android 中文API (65) —— BluetoothClass[蓝牙]
前言 本章内容是android.bluetooth.BluetoothClass,为Android蓝牙部分的章节翻译.用于描述远端设备的类型,特点等信息,通过getBluetoothClass()方法 ...
- android中文api(79)——Gallery
前言 本章内容是 android.widget.Gallery,版本为Android 2.3 r1,翻译来自"henly.zhang",欢迎大家访问他的博客:http://www. ...
- Android中文API
Android中文API http://www.android-doc.com/index.html
- Android 中文 API (29) —— CompoundButton
前言 本章内容是android.widget.CompoundButton,翻译来自德罗德,再次感谢德罗德 !期待你一起参与Android API 的中文翻译,联系我over140@gmail.com ...
随机推荐
- Yii学习笔记之中的一个(安装与基础环境的配置)
0. 下载yii http://www.yiiframework.com/download/ 1. 訪问 basic 基础文件夹下的 web 文件夹 出现图1 的错误 : Invalid Con ...
- ZOJ 2913 Bus Pass (近期的最远BFS HDU2377)
题意 在全部城市中找一个中心满足这个中心到全部公交网站距离的最大值最小 输出最小距离和满足最小距离编号最小的中心 最基础的BFS 对每一个公交网站BFS dis[i]表示编号为i的点到全部公交网 ...
- 51NOD 1686 第K大区间 二分
第k大区间 定义一个区间的值为其众数出现的次数.现给出n个数,求将所有区间的值排序后,第K大的值为多少. Input 第一行两个数n和k(1<=n<=100000,k<=n* ...
- 几种AutoLayout自动布局所经常使用的布局约束类型
width表示约束ui控件的固定宽度 height表示约束ui控件的固定高度 Leading Space to Superview 与父视图的左边界线保持固定距离 Trailing Space to ...
- 在eclipse环境下使用maven install 命令碰到native2ascii-utf8问题解决方案
报错语句:Failed to execute goal org.codehaus.mojo:native2ascii-maven-plugin:1.0-beta-1:native2ascii (nat ...
- 1.Thinkphp入门--框架介绍
1.Thinkphp款家最早诞生于2006年初,最初名叫fsc,2007年元旦改名thinkphp,由国人自主开发的框架,有中文的文档和社区 2.Tinkphp下载: 官网:http://www.th ...
- 洛谷P3356 火星探险问题(费用流)
题目描述 火星探险队的登陆舱将在火星表面着陆,登陆舱内有多部障碍物探测车.登陆舱着陆后,探测车将离开登陆舱向先期到达的传送器方向移动.探测车在移动中还必须采集岩石标本.每一块岩石标本由最先遇到它的探测 ...
- DOM基础知识(Node对象、Element对象)
5.Node对象 u 遍历节点 u 父节点 .parentNode - 获取父节点—> 元素节点或文档节点 .parentElement - 获取父元素节点—> 元素节点 u 子节 ...
- deploy sql clr
1, create strong signed key file 2, create asymmetric key
- Java基础之Colloction
0 引言 以下是介绍Java有关集合类,以及对应每个类的用途,同时进行比较集合类的不同特点来让我们深入了解. 1 Collction接口 Collection是最基本的集合接口,一个Collectio ...