有getLayoutInflater()和.getSystemService(Context.LAYOUT_INFLATER_SERVICE)之间的区别 [英] Is there any difference between getLayoutInflater() and .getSystemService(Context.LAYOUT_INFLATER_SERVICE)

查看:803
本文介绍了有getLayoutInflater()和.getSystemService(Context.LAYOUT_INFLATER_SERVICE)之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的不的答案会平静我。 如果有任何差别那么它是什么?

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()到<一个href="http://developer.android.com/reference/android/view/LayoutInflater.html#from%28android.content.Context%29">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;
}

这篇关于有getLayoutInflater()和.getSystemService(Context.LAYOUT_INFLATER_SERVICE)之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆