LayoutInflater
来源:互联网 发布:淘宝充q币怎么没到账 编辑:程序博客网 时间:2024/05/21 10:09
在实际开发种LayoutInflater这个类还是非常有用的,它的作用类似于 findViewById(),
不同点是:
LayoutInflater 是用来找layout下xml布局文件,并且实例化!
findViewById() 是找具体xml下的具体 widget控件(如:Button,TextView等)。
一般来讲,我们用LayoutInflater做一件事:inflate。
目的都是把xml表述的layout转化为View。这个类是用来实例化布局的 XML文件到相应的视图对象。它是不能直接使用——使用 getlayoutinflater()或getSystemService (String)来检索一个标准的 LayoutInflater实例已经与当前上下文和为你的设备上运行的正确配置
获取LayoutInflater对象三种方法:
1、LayoutInflater inflater=getLayoutInflater();
2、LayoutInflater inflater=(LayoutInflater)mContext.getSystemServic(LAYOUT_INFLATER_SERVICE);
3、LayoutInflater inflater=LayoutInflater.from(context); //这种方法在重写BaseAdapter时常用
他们实质是一样的,请看源码
public static LayoutInflater from(Context context) {
LayoutInflater LayoutInflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (LayoutInflater == null) {
throw new AssertionError("LayoutInflater not found.");
}
return LayoutInflater;
}
不同点是:
LayoutInflater 是用来找layout下xml布局文件,并且实例化!
findViewById() 是找具体xml下的具体 widget控件(如:Button,TextView等)。
一般来讲,我们用LayoutInflater做一件事:inflate。
目的都是把xml表述的layout转化为View。这个类是用来实例化布局的 XML文件到相应的视图对象。它是不能直接使用——使用 getlayoutinflater()或getSystemService (String)来检索一个标准的 LayoutInflater实例已经与当前上下文和为你的设备上运行的正确配置
获取LayoutInflater对象三种方法:
1、LayoutInflater inflater=getLayoutInflater();
2、LayoutInflater inflater=(LayoutInflater)mContext.getSystemServic(LAYOUT_INFLATER_SERVICE);
3、LayoutInflater inflater=LayoutInflater.from(context); //这种方法在重写BaseAdapter时常用
他们实质是一样的,请看源码
public static LayoutInflater from(Context context) {
LayoutInflater LayoutInflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (LayoutInflater == null) {
throw new AssertionError("LayoutInflater not found.");
}
return LayoutInflater;
}
0 0
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- 差分约束系统详解
- Rol租车网项目总结
- git笔记--分支
- ubuntu lamp yii2
- java引用
- LayoutInflater
- 哈哈,用FlexGrid做开发,轻松处理百万级表格数据
- Python按行读取大文件
- iOS 支付宝集成
- 人需得稳重
- stm32 死区
- Java中为何要定义抽象类
- 【dp】【倍增】花花的聚会
- shell中特殊字符$$ $# $0