对LayoutInflater的简单理解
来源:互联网 发布:淘宝怎么转接人工服务 编辑:程序博客网 时间:2024/05/18 02:44
LayoutInflater的获得实例的三种方法
1.LayoutInflater inflater = getLayoutInflater(); //调用Activity的getLayoutInflater()2.LayoutInflater localinflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);3. LayoutInflater inflater = LayoutInflater.from(context);
众所周知,inflater.inflate的三种加载模式
1.inflate(layoutId, null );2.inflate(layoutId, root, false );3.inflate(layoutId, root, true )
通过观察下面的源码我们可以知道,1和2是进入了第二个条件即没有附带参数,即你在xml写的参数是不会起作用的,要想参数起作用就只有用第3的一个方法。
// We are supposed to attach all the views we found (int temp)// to root. Do that now.if (root != null && attachToRoot) { root.addView(temp, params);}// Decide whether to return the root that was passed in or the// top view found in xml.if (root == null || !attachToRoot) { result = temp;}
其次对于1,2也是有区别的,1是直接加载出一个组件,2是加载出一个组件后还要将组件放到root布局里面去,最后返回的视图就是组件加入后的视图。所以1,2就必须要动态填入参数,wrap_content或match_parent。1还需要addView()将他加入父布局如下图:
最后福利一个非常有用的链接:http://blog.csdn.net/yanbober/article/details/45970721
0 0
- 对LayoutInflater的简单理解
- 对Android LayoutInflater的理解
- Android,LayoutInflater的简单理解
- 自己对LayoutInflater理解
- LayoutInflater简单理解
- 使用LayoutInflater的理解
- LayoutInflater的一些理解
- LayoutInflater的简单认识
- 对RMI的简单理解
- 对MVC的简单理解
- 对JAVA简单的理解
- 对buffer的简单理解
- 对委托的简单理解
- 对selector的简单理解
- 对句柄的简单理解
- 对json的简单理解
- 对XML的简单理解
- 对Application的简单理解
- 【HTTP指南】杂
- 漫谈云计算网络(一):云计算网络技术介绍
- android webview字体大小的设置
- object-c类与对象
- HDR in OpenGL
- 对LayoutInflater的简单理解
- 儿童英语读物推荐Say Readers Tongs 分级阅读绘本
- NSThread(多线程003)
- big data landscape
- UIGraphics 绘制饼图
- 游戏引擎起步杂谈
- Beamforming技术在专网宽带无线通信系统中的应用
- javascript函数调用方式总结(共四种)-理解this
- 超实用的样式写法