这两者之间有什么区别吗?
inflater = (LayoutInflater) LayoutInflater.from(context);
(从上下文获取布局填充器)inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
(通过系统服务获取布局填充器)
这两者之间有什么区别吗?
inflater = (LayoutInflater) LayoutInflater.from(context);
(从上下文获取布局填充器)inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
(通过系统服务获取布局填充器)目前来看,您可以通过查看LayoutInflater
源代码了解到,from()
将抛出一个Exception
而不是返回null
,但除此之外它们是相同的。
个人而言,我大多数时候都使用getLayoutInflater()
。