Android 高效地创建一个平面布局器
我的问题是,创建Android 高效地创建一个平面布局器,android,android-context,android-inflate,Android,Android Context,Android Inflate,我的问题是,创建LayoutInflater实例的最佳方法是什么?两者之间有什么区别吗 LayoutInflater inflater = LayoutInflater.from(context); 及 哪一个是更好的解决方案?也欢迎其他解决办法 谢谢。如果您查看LayoutInflater.java源文件,您会发现 /** * Obtains the LayoutInflater from the given context. */ public static LayoutInflate
LayoutInflater
实例的最佳方法是什么?两者之间有什么区别吗
LayoutInflater inflater = LayoutInflater.from(context);
及
哪一个是更好的解决方案?也欢迎其他解决办法
谢谢。如果您查看LayoutInflater.java源文件,您会发现
/**
* Obtains the LayoutInflater from the given 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;
}
因此,第二种解决方案应该比第一种有点效率。
/**
* Obtains the LayoutInflater from the given 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;
}