实现LayoutInflater的实例化共有3种方法,
1 通过SystemService获得
LayoutInflaterinflater = (LayoutInflater)context.getSystemServices(Context.LAYOUT_INFLATER_SERVICES);
Viewview = inflater.inflate(R.layout.main, null);
2 从给定的context中获得
LayoutInflaterinflater = LayoutInflater.from(context);
Viewview = inflater.inflate(R.layout.mian, null);
3 LayoutInflaterinflater =getLayoutInflater();(在Activity中可以使用,实际上是View子类下window的一个函数)
Viewlayout = inflater.inflate(R.layout.main, null);
原文:http://www.androidstar.cn/layoutinflater和inflate方法的用法-自定义view中加载xml布局/
本文介绍了在Android开发中LayoutInflater的三种实例化方式:通过SystemService获取、从给定的context中获得及在Activity中直接调用getLayoutInflater()方法。每种方法都提供了具体的代码示例。
8476

被折叠的 条评论
为什么被折叠?



