您的位置:首页 > 移动开发 > Android开发

Android 之 LayoutInflater

2015-12-14 13:43 716 查看
1.在实际开发过程中,LayoutInflater 这个类是非常有用的,它的作用类似于findViewbyId(),不同点是LayoutInflater是用来找Res/Layout/下面的xml布局文件的具体控件

2.作用:

a.对于一个没有被加载入或者想要动态加载的界面,都需要LayoutInflate() 来实现

b.对于一个已经载入的界面。可以使用findViewById()来实现

3.获得layoutInflater的三方法:

a.


LayoutInflater inflater= (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);					//第一个参数布局文件
View view=inflater.inflate(R.layout.ID, null);


b.

LayoutInflater inflater=LayoutInflater.from(this);
View view=inflater.inflate(R.layout.ID,null);


c.

LayoutInflater inflater= getLayoutInflater();
View view=inflater.inflate(R.layout.ID,null);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: