LayoutInflater 动态加载布局文件
2013-08-01 09:15
399 查看
LayoutInflater有三种方式加载布局文件:
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.main, null)
LayoutInflater inflater = LayoutInflater.from(context); View layout = inflater.inflate(R.layout.main, null);
LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.main, null);
inflater.inflate(resourceId, rootId);第一个参数是要加载布局的id,第二个参数时给指定布局的外部套一层父布局,如果不需要就直接传null
另外,还有一个方法,inflater.inflate(resourceId, rootId, attachToRoot)
注意点:LayoutInflater加载的布局文件最好套上一个parent layout,否则在view上设置的layout_width和layout_height将不起作用,因为layout_类别的视图属性是设置view在父视图中的大小的,并不是指定view本身的大小。
相关文章推荐
- LayoutInflater 动态加载布局文件
- android Activity.this.getLayoutInflater()::动态加载布局文件,实现弹窗效
- Android--使用LayoutInflater加载布局文件的三种方法
- LayoutInflater的使用:动态加载布局
- Android-LayoutInflater的使用(android 动态布局文件)
- 动态加载布局LayoutInflater.inflate()源代码解析
- LayoutInflater的使用:动态加载布局
- layoutInflater动态加载布局
- LayoutInflater 加载布局文件失败原因
- android控件学习二:使用LayoutInflater动态加载布局和操作控件
- LayoutInflater 动态加载布局
- LayoutInflater动态加载布局方法实例
- Android-LayoutInflater的使用(android 动态布局文件)
- Android布局加载之LayoutInflater
- Androiid 如何动态加载assets目录下的xml布局文件(包括Drawable xml)
- Android 在Class文件里动态调用一个layout布局文件
- 【边做项目边学Android】知识点:动态设置布局LayoutInflater
- android动态加载布局文件示例
- android动态加载布局文件示例
- Android学习笔记_31_通过后台代码生成View对象以及动态加载XML布局文件到LinearLayout