android学习笔记---Android LayoutInflater和infalter()方法详解
来源:互联网 发布:ps cc2017 mac 中文包 编辑:程序博客网 时间:2024/06/03 20:55
本文转自:http://www.cnblogs.com/top5/archive/2012/05/04/2482328.html
http://www.cnblogs.com/shitianzeng/articles/2323427.html
inflate 方法通过 sdk 的 api 文档,可以知道该方法有以下几种过载形式,返回值均是 View 对象,如下:
public View inflate (int resource, ViewGroup root) public View inflate (XmlPullParser parser, ViewGroup root) public View inflate (XmlPullParser parser, ViewGroup root, boolean attachToRoot) public View inflate (int resource, ViewGroup root, boolean attachToRoot)
示意代码:
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.custom,(ViewGroup)findViewById(R.id.test)); //EditText editText = (EditText)findViewById(R.id.content);// error EditText editText = (EditText)view.findViewById(R.id.content);
对于上面代码,指定了第二个参数 ViewGroup root,当然你也可以设置为 null 值。
如果提供root(不传null)时,返回值其实就是这个root,这个方法就是把xml解析成view之后挂载这个root下。
如果传null(不提供root),返回值也是View,它就是xml布局里面的根节点
- android学习笔记---Android LayoutInflater和infalter()方法详解
- Android学习笔记 LayoutInflater
- 【Android】 LayoutInflater和SetContentView详解
- Android学习之LayoutInflater类和inflate()方法的使用
- [Android]LayoutInflater的inflate方法半详解
- android-----LayoutInflater的inflate方法详解
- Android LayoutInflater.inflate()方法参数详解
- android基础学习002_Android LayoutInflater详解
- android 入门学习笔记 LayoutInflater的使用
- Android UI 详解之LayoutInflater和setContentView
- Android LayoutInflater详解
- Android LayoutInflater详解
- Android LayoutInflater详解
- Android LayoutInflater详解
- Android LayoutInflater详解
- Android 的LayoutInflater详解
- Android LayoutInflater详解
- Android LayoutInflater详解
- memcached stats运行状态 各项解读
- dp cf478D
- Android开发之SQLite数据库详解
- test
- nyoj-277-车牌号
- android学习笔记---Android LayoutInflater和infalter()方法详解
- NYOJ 253LK的旅行(凸包 对踵点)
- TRIZ系列-创新原理-18-机械振动原理
- Maven中央仓库——你可能不知道的细节
- java小程序——给数组随机赋值,查找输入的值以及冒泡和选择排序数组并输出
- 【android】优秀的UI资源网站集合
- Codeforces Round #273 (Div. 2)
- Hibernate系列学习之(二) 多对一、一对一、一对多、多对多的配置方法
- 【线段树】基本写法,区间极值,区间延迟更新,多延迟标签