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
。