最近学习安卓基础发现同一个需求不同视频里用的方法不一样,有的用getlayoutinflater().from(this).inflate ,有的用View.inflate,想知道这两个方法有什么区别
你说的是 LayoutInflater.from(context).inflate 吧
其实View.inflate里面间接调用了 LayoutInflater.from(context).inflate
给你看一下View.inflate的源码
public static View inflate(Context context, @LayoutRes int resource, ViewGroup root) {
LayoutInflater factory = LayoutInflater.from(context);
return factory.inflate(resource, root);
}