gpt4 book ai didi

android - 充气 View 的差异

转载 作者:行者123 更新时间:2023-11-30 00:42:32 27 4
gpt4 key购买 nike

想问一下。有什么区别:

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

引用:http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/view/LayoutInflater.java#LayoutInflater.from%28android.content.Context%29

关于android - 充气 View 的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42334008/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com