android LayoutInflater.inflate()的参数及其用法
来源:互联网 发布:域名购买后怎么使用 编辑:程序博客网 时间:2024/05/18 03:52
转载:http://blog.csdn.net/lovexieyuan520/article/details/9036673
很多人在网上问LayoutInflater类的用法,以及inflate()方法参数的含义,现解释如下:
inflate()的作用就是将一个用xml定义的布局文件查找出来,注意与findViewById()的区别,inflate是加载一个布局文件,而findViewById则是从布局文件中查找一个控件。
1.获取LayoutInflater对象有三种方法
LayoutInflater inflater=LayoutInflater.from(this);
LayoutInflater inflater=getLayoutInflater();
LayoutInflater inflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
2.关于LayoutInflater类inflate(int resource, ViewGroup root, boolean attachToRoot)方法三个参数的含义
resource:需要加载布局文件的id,意思是需要将这个布局文件中加载到Activity中来操作。
root:需要附加到resource资源文件的根控件,什么意思呢,就是inflate()会返回一个View对象,如果第三个参数attachToRoot为true,就将这个root作为根对象返回,否则仅仅将这个root对象的LayoutParams属性附加到resource对象的根布局对象上,也就是布局文件resource的最外层的View上,比如是一个LinearLayout或者其它的Layout对象。
attachToRoot:是否将root附加到布局文件的根视图上
这就是我的理解,如有不明白或者有误,请广大网友给我留言,共同进步!
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- 关于android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其功能
- android LayoutInflater.inflate()的参数介绍
- 排序算法
- localhost 与 127.0.0.1 的区别
- Unicode与UTF-8互转(C语言实现)
- 15分钟轻松定制基于VIM的IDE
- 谁能拯救孩子的想象力
- android LayoutInflater.inflate()的参数及其用法
- 备份linux系统
- 有关ogre里MeshManager::createPlane()函数的一点补充(转)
- 二分查找
- python3 自动获取公网ip并发送邮件通知
- SQLSERVER2000启动失败
- 面试时95%会问到的问题
- 剪枝———讲解
- 中国移动飞信发送接口(Fetion API)