6、Android之LayoutInflater.inflate()
LayoutInflater.inflate()的作用就是将一个xml定义的布局文件实例化为view控件对象;
与findViewById区别:
LayoutInflater.inflate是加载一个布局文件;
findViewById则是从布局文件中查找一个控件;
一.获取LayoutInflater对象有三种方法
LayoutInflater inflater=LayoutInflater.from(context);
LayoutInflater inflater=getLayoutInflater();在Activity中可以使用,实际上是View子类下window的一个函数
LayoutInflater inflater=(LayoutInflater)context.getSystemService(LAYOUT_INFLATER_SERVICE);
二:inflate 参数
public View inflate(int resource, ViewGroup root, boolean attachToRoot) :
reSource:View的layout的ID root:需要附加到resource资源文件的根控件,inflate()会返回一个View对象,如果第三个参数
attachToRoot为true,就将这个root作为根对象返回,否则仅仅将这个root对象的LayoutParams属性附加到resource对象的根布局对象
上,也就是布局文件resource的最外层的View上。如果root为null则会忽略view根对象的LayoutParams属性(注意)。
attachToRoot:是否将root附加到布局文件的根视图上
简单来讲:
1. 如果root为null,attachToRoot将失去作用,设置任何值都没有意义。
2. 如果root不为null,attachToRoot设为true,则会在加载的布局文件的最外层再嵌套一层root布局。
3. 如果root不为null,attachToRoot设为false,则root参数失去作用。
4. 在不设置attachToRoot参数的情况下,如果root不为null,attachToRoot参数默认为true。
6、Android之LayoutInflater.inflate()的更多相关文章
- android LayoutInflater.inflate()的参数介绍
LayoutInflater.inflate()的作用就是将一个xml定义的布局文件实例化为view控件对象: 与findViewById区别: LayoutInflater.inflate是加载一个 ...
- Android LayoutInflater.inflate使用上的问题解惑
最近在在使用LayoutInflater.inflate方法时遇到了一些问题,以前没有仔细看过此类的使用方法,故将其记录下来,方便日后查阅. 相信大家都知道LayoutInflater.inflate ...
- [Xamarin] 使用LayoutInflater.Inflate載入預先設計好的Layout並使用 (转帖)
開發的時候,一定會把一些東西設計成元件,並且可以多次使用,今天紀錄一篇比較簡單的方法,可以載入事先做好的Layout 並且給予事件 介紹一下範例: Main.axml: <?xml versio ...
- Android高手进阶教程(五)之----Android 中LayoutInflater的使用!
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://weizhulin.blog.51cto.com/1556324/311450 大 ...
- Android中LayoutInflater的使用
Inflater英文意思是膨胀,在Android中应该是扩展的意思吧. LayoutInflater 的作用类似于 findViewById(),不同点是LayoutInflater是用来找layou ...
- android中LayoutInflater详解与使用
android的LayoutInflater用来得到一个布局文件,也就是xxx.xml,而我们常用的findviewbyid是用来取得布局文件里的控件或都布局.inflater即为填充的意思,也就是说 ...
- setContentView()与LayoutInflater.inflate()作用
@Override protected void onCreate(Bundle savedInstanceState) { try{ super.onCreate(savedInstanceS ...
- at android.view.LayoutInflater.createViewFromTag的错误原因
创建对话框时出现下面的错误: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean ...
- 【Android】LayoutInflater
LayoutInflater的作用 LayoutInflater的作用类似于findViewById(). 不同点是: LayoutInflater是用来找res/layout/下的xml布局文件,并 ...
随机推荐
- Pattern Recognition for Cell-free DNA - Github
一直都没有找到生信领域简单易懂的机器学习案例,这回算是逮到一个了:机器学习识别cfDNA OpenGene/CfdnaPattern
- 把本地仓库工程上传到github上和从gitbu同步工程到本地
1.在本地产生秘钥和公钥 [root@jacky git_project]# ssh-keygen -t rsa -C "jacky-lulu@1073740572@qq.com" ...
- Python下载进度条
import dialog,e32,appuifw def ru(x):return x.decode('utf8') def qu(): appuifw.note(ru('已取消')) wait.c ...
- loadrunner关联——对服务器返回的数据选择性提交
在跟进项目的过程中,才体会到自己之前闷头看书再写小小的测试程序验证的学习方式很没有效率,知道动态关联,却也只是会参数化式的动态关联,这种关联是我们预先知道要提交的数据而进行的关联:更高一级的可能就是使 ...
- List接口、Set接口、Map接口的方法
一.Collection接口中的方法介绍 int size();返回此Collection中的元素数 boolean isEmpty(); 判断是否为空 boolean containsAll(Col ...
- cocoapod集成失败,无法找到头文件的解决办法
在终端更新pod的时候,提示警告: target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support ...
- 常看常遇见之一——BS架构VS CS架构
常看常遇见之一——BS架构VS CS架构 1.BS架构 即Browser/Server(浏览器/服务器)结构,是随着Internet技术的兴起,对C/S结构的一种变化或者改进的结构.在这种结构下,用户 ...
- ubuntu16.04 orbslam ./build.sh 出错eigen
错误如下: /home/a/ORB_SLAM2/src/Optimizer.cc:1244:1: required from here/usr/include/eigen3/Eigen/src/Cor ...
- <button>标签与<input type="button">标签
<script type="text/javascript" src="/jquery-1.11.3.min.js"></script> ...
- 学习docker
虚拟机下Ubuntu环境 1.sudo apt-get update 2.sudo apt-get install docker.io 3.在daocloud(http://www.daocloud. ...