好记性不如铅笔头

android, 编程

Android应用开发笔记:inflate

Inflative的方法有很多,这里简单的备份一下:

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);

View layout = View.inflate(this, R.layout.main, null);

 备注:

参考网站:

http://my.eoe.cn/addcn/archive/4215.html 】【 http://www.cnblogs.com/loyea/archive/2013/04/27/3047248.html 】

发表评论

14 + 6 =

此站点使用 Akismet 来减少垃圾评论。了解我们如何处理您的评论数据