Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android GetLayoutFlater()和.getSystemService(Context.LAYOUT\u充气器\u服务)之间有什么区别吗_Android_Android Layout_Android Widget - Fatal编程技术网

Android GetLayoutFlater()和.getSystemService(Context.LAYOUT\u充气器\u服务)之间有什么区别吗

Android GetLayoutFlater()和.getSystemService(Context.LAYOUT\u充气器\u服务)之间有什么区别吗,android,android-layout,android-widget,Android,Android Layout,Android Widget,简单的“不”回答会让我平静下来。 如果有任何区别,那么它是什么?这就是定义布局器的方式 LayoutInflater inflater = (LayoutInflater)context.getSystemService (Context.LAYOUT_INFLATER_SERVICE); 而getLayoutInflater()只是通过返回LayoutInflater,提供“快速访问窗口从其上下文检索到的LayoutInflater实例”(从) 类似地,getSystemService(Co

简单的“不”回答会让我平静下来。
如果有任何区别,那么它是什么?

这就是定义布局器的方式

LayoutInflater inflater = (LayoutInflater)context.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
getLayoutInflater()
只是通过返回LayoutInflater,提供“快速访问窗口从其上下文检索到的LayoutInflater实例”(从)

类似地,
getSystemService(Context.LAYOUT\u INFLATER\u SERVICE)
用于检索LayoutInflater以在该上下文中膨胀布局资源

因此,实际上两者之间没有差别

来源:

只要调用
getLayoutFlater()
的活动或窗口与调用
getSystemService()
的上下文相同,就没有区别


Proof您可以将
getLayoutInflater()
返回的LayoutInflater跟踪到,您可以从源代码中看到这只是
getSystemService()
的快捷方式:

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;
}

至少有一种情况是

getSystemService(上下文布局\充气机\服务)

必须使用,而不是对应的

GetLayoutFlater

这种情况发生在任意对象类中。例如,我有一个类调用objectA的实例。在objectA中,我想将视图膨胀到父视图上(发生在ArrayAdapter中,它膨胀其listview上的自定义行)。在这种情况下,上下文。GetLayoutFlater不起作用,因为没有与上下文关联的活动或窗口。只有获取系统服务(Context.LAYOUT\u INFLATER\u SERVICE)才合适。


没有区别。

请不要剽窃文档。使用SO的报价格式
并引用源代码。其他证明:
GetLayoutFlater()==getSystemService(Context.LAYOUT\u INFLATER\u SERVICE)
返回
true
否,
=
返回
true
,因为这两个实例相同。如果
=
返回
true
,那么
equals()
,如果它(很好地)实现,将始终返回
true