对LayoutInflater的简单理解
2016-05-09 14:37
465 查看
LayoutInflater的获得实例的三种方法
众所周知,inflater.inflate的三种加载模式
通过观察下面的源码我们可以知道,1和2是进入了第二个条件即没有附带参数,即你在xml写的参数是不会起作用的,要想参数起作用就只有用第3的一个方法。
其次对于1,2也是有区别的,1是直接加载出一个组件,2是加载出一个组件后还要将组件放到root布局里面去,最后返回的视图就是组件加入后的视图。所以1,2就必须要动态填入参数,wrap_content或match_parent。1还需要addView()将他加入父布局如下图:
最后福利一个非常有用的链接:/article/1503765.html
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()将他加入父布局如下图:
最后福利一个非常有用的链接:/article/1503765.html
相关文章推荐
- (原)配置vs2013使用intel的IPP库
- Linux搭建SVN服务器
- Beamforming技术在专网宽带无线通信系统中的应用
- 带武器的游戏角色类
- 游戏引擎起步杂谈
- 第六章 开发一个MapReduce应用 第一节 配置
- javascript函数调用方式总结(共四种)-理解this
- 常用正则表达式应用
- android webview字体大小的设置
- 笔记-bootstrap span 无效
- Linux下安装theano
- zabbix监控工具
- Java程序运行机制
- HDR in OpenGL
- centos7上consul的集群安装
- ASP.NET页面中去除VIEWSTATE视
- ASP.NET获取IP的6种方法 ( 转)
- Connection closed by foreign host
- UIGraphics 向图片上写字
- Android文字自滚动textview