美文网首页
LayoutInflater和inflate()方法的用法 (自

LayoutInflater和inflate()方法的用法 (自

作者: 栗子爸0803 | 来源:发表于2015-08-10 10:04 被阅读0次

实现LayoutInflater的实例化共有3种方法:

1. 通过SystemService获得

LayoutInflater inflater = (LayoutInflater)context.getSystemServices(Context.LAYOUT_INFLATER_SERVICES);

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

2. 从给定的context中获得

LayoutInflater inflater = LayoutInflater.from(context);

View view = inflater.inflate(R.layout.mian, null);

3.

LayoutInflater inflater = getLayoutInflater();(在Activity中可以使用,实际上是View子类下window的一个函数)

Viewlayout = inflater.inflate(R.layout.main, null);

相关文章

网友评论

      本文标题:LayoutInflater和inflate()方法的用法 (自

      本文链接:https://www.haomeiwen.com/subject/xjliqttx.html