Android LayoutInflate(一)
来源:互联网 发布:我要开淘宝网店怎么开 编辑:程序博客网 时间:2024/06/05 08:00
推卸责任和默默填坑,怎么选择?
LayoutInflater
项目中,我们通常通过LayoutInflater来找res/layout/下的xml布局文件,并且实例化。
怎么获取LayoutInflater
LayoutInflater 是一个抽象类,在文档中如下声明:
public abstract class LayoutInflater extends Object`获得 LayoutInflater 实例的三种方式
//Activity调用getLayoutInflater() 1. LayoutInflater inflater = getLayoutInflater();2. LayoutInflater inflater = LayoutInflater.from(context); 3. LayoutInflater inflater = (LayoutInflater)context.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
其实最后还是通过第三种方式获取:
Activity 的 getLayoutInflater() 方法是调用 PhoneWindow 的getLayoutInflater()方法,看一下该源代码:
public PhoneWindow(Context context){ super(context); mLayoutInflater = LayoutInflater.from(context);}
可以看出它其实是调用LayoutInflater.from(context)
。
LayoutInflater.from(context):
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;}
最后调用 context.getSystemService()。
0 0
- Android LayoutInflate(一)
- Android LayoutInflate.Inflate(二)
- Android LayoutInflate.SetFactory( )(三)
- Android LayoutInflate
- Android - LayoutInflate用法
- Android - LayoutInflate用法
- Android - LayoutInflate用法
- 【转】 Android - LayoutInflate用法
- Android - LayoutInflate用法
- Android LayoutInflate的基本知识
- LayoutInflate
- LayoutInflate
- 使用LayoutInflate(视图扩充器)
- Android layoutInflate.inflate 方法详解,removeView()错误解决
- android LayoutInflate.inflate源码分析及使用区分
- Android LayoutInflate深度解析 给你带来全新的认识
- layoutInflate 解析
- layoutinflate应用
- MYSQL 优化的笔记
- shell 脚本为多个指定的目录创建报告
- 如何安装Java环境
- Java反射获取类和对象
- lucene 各个版本的下载地址
- Android LayoutInflate(一)
- Android 复习4 神奇的问题 杂谈
- gcc的优化选项
- ApiCloud (1)
- JAVA中多线程初体验
- 我也来写个小总结---小白学git
- 7_4_L题 Cheerleaders 题解[uva 11806](容斥)
- SQL Server Replication II
- 路由器开发相关知识总结 —— IEEE1588基础知识