inflate方法与findViewById的区别
2016-02-02 10:47
316 查看
转自http://www.cnblogs.com/tinyphp/p/3891859.html
LayoutInflater作用是将layout的xml布局文件实例化为View类对象。
对于一个没有被载入或者想要动态载入的界面,都需要使用LayoutInflater.inflate()来找 res/layout下的 xml 布局文件,并且实例化为View类对象;
获取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();
//在Activity中可以使用,实际上是View子类下window的一个函数
View layout = inflater.inflate(R.layout.main, null);
·findViewById() 是找具体 xml 布局文件中的具体 widget 控件(如:Button、TextView 等)。
LayoutInflater作用是将layout的xml布局文件实例化为View类对象。
对于一个没有被载入或者想要动态载入的界面,都需要使用LayoutInflater.inflate()来找 res/layout下的 xml 布局文件,并且实例化为View类对象;
获取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();
//在Activity中可以使用,实际上是View子类下window的一个函数
View layout = inflater.inflate(R.layout.main, null);
·findViewById() 是找具体 xml 布局文件中的具体 widget 控件(如:Button、TextView 等)。
相关文章推荐
- 用css+js制作可自动伸缩导航栏
- phalcon-入门篇3(优美的URL与Config)
- UVA 674_Coin Change
- CentOS 7.x设置自定义开机启动,添加自定义系统服务
- Linux 安装JDK
- 正则表达式小记
- nodejs基础(二)
- SQL Server之内连接 左连接 右连接 全连接 交叉连接
- 关于 自己遇到的内存溢出问题
- Android之代码设置selector
- LeetCode——Path Sum II
- 书签
- 正则表达式
- git文件存储原理解析(八)
- git文件存储原理解析(八)
- vs2008 warning4390
- hdoj 2065“红色病毒”问题
- Spring Aop
- Ubuntu14.04安装nginx稳定版本步骤
- HTTP协议详解