简单的不的答案会平静我。 如果有任何差别那么它是什么?
Simple "No" answer will calm me. If there is any difference then what it is?
没有
只要在活动或窗口,调用 getLayoutInflater()
有相同的背景下,会叫 getSystemService()
,没有差别。
As long as the Activity or Window that calls getLayoutInflater()
has the same Context that would call getSystemService()
, there is no difference.
证明您可以通过跟踪 getLayoutInflater返回LayoutInflater()
到LayoutInflater.from()你可以看到这只是一个快捷键 getSystemService()
从源头code:
Proof You can trace the LayoutInflater returned by getLayoutInflater()
to LayoutInflater.from() and you can see this is just a shortcut for getSystemService()
from the source code:
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;
}