码迷,mamicode.com
首页 > 其他好文 > 详细

inflate方法与findViewById的区别

时间:2014-08-05 13:48:19      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   文件   cti   div   log   

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 等)。

inflate方法与findViewById的区别,布布扣,bubuko.com

inflate方法与findViewById的区别

标签:style   blog   color   使用   文件   cti   div   log   

原文地址:http://www.cnblogs.com/tinyphp/p/3891859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!