android LayoutInflater类的理解及用法
来源:互联网 发布:js 多选框选中 编辑:程序博客网 时间:2024/06/14 23:31
1. LayoutInflater.inflate()的作用就是将一个用xml定义的布局文件查找出来
注意与findViewById()的区别,inflate是加载一个布局文件,而findViewById则是从布局文件中查找一个控件。
2.获取LayoutInflater对象有三种方法
LayoutInflater inflater=LayoutInflater.from(this);
LayoutInflater inflater=getLayoutInflater();
LayoutInflater inflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
这三种方法用的场合不太一样, 但效果是一样的,即实例化出来一个LayoutInflater类对象.
3.关于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附加到布局文件的根视图上
参考链接:
http://www.open-open.com/lib/view/open1328837587484.html
http://blog.csdn.net/lovexieyuan520/article/details/9036673
http://www.eoeandroid.com/thread-272744-1-1.html
(以下内容如果不感兴趣,可以跳过...)
另外说一下, 设置gridview高度的问题, 即这个问题: http://www.eoeandroid.com/thread-272744-1-1.html
如果用的方法 inflate(xml, null) 出来的布局, 则需要手动设置高度等一些参数.
如果用的方法 inflate(xml, parentView, false)出来的布局, 则可以直接在 xml文件中写上高度及宽度.
- android LayoutInflater类的理解及用法
- Android LayoutInflater的用法
- android--LayoutInflater作用及用法
- Android,LayoutInflater的简单理解
- 对Android LayoutInflater的理解
- Android中LayoutInflater的用法
- 关于Android LayoutInflater的用法
- LayoutParams的用法,及LayoutInflater区别
- LayoutParams的用法,及LayoutInflater区别
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- Android:LayoutInflater的inflate函数用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater的两种用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- android LayoutInflater.inflate()的参数及其用法
- notepad++的tab设置为4个空格
- JavaScript中的深复制和浅复制
- 同步屏障CyclicBarrier
- 【排序】洛谷 P1104 生日
- 容器的功能
- android LayoutInflater类的理解及用法
- java 多线程小例子2
- 父窗口与子窗口调用
- 牛顿迭代法求平方根
- 驱动调试之printk的原理
- USB HID简介??????
- Oracle12c多租户如何连接到CDB或PDB、CDB与PDB容器切换
- github干货地址分享
- Android Log