想问一下。有什么区别:
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
。
关于android - 充气 View 的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42334008/