充气视图的差异
Difference in inflating views
想问一下。有什么区别:
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
并且:
LayoutInflater layoutInflater = LayoutInflater.from(this);
?
差别不大。
LayoutInflater#from(Context 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;
}
所以,LayoutInflater#from
里面用的也是一样的context.getSystemService
。
想问一下。有什么区别:
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
并且:
LayoutInflater layoutInflater = LayoutInflater.from(this);
?
差别不大。
LayoutInflater#from(Context 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;
}
所以,LayoutInflater#from
里面用的也是一样的context.getSystemService
。