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

Android--使用LayoutInflater加载布局文件的三种方法

2015-10-15 22:12 706 查看
LayoutInflater的作用类似于 findViewById(),

不同点是LayoutInflater是用来找layout文件夹下的xml布局文件,并且实例化!

而 findViewById()是找具体某一个xml下的具体 widget控件(如:Button,TextView等)。

使用LayoutInflater来获取布局文件有三种方式:

第一种方式

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


第二种方式

LayoutInflater inflater = getLayoutInflater();
iew layout = inflater.inflate(R.layout.order, null);


第三种方式

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