使用LayoutInflater
和静态方法View.inflate()
的主要区别是什么?使用它们中的任何一个有什么缺点吗?或者它们有不同的用途?
发布于 2014-05-28 18:27:04
如果查看View.inflate()
的源代码,我们会看到以下内容:
public static View inflate(Context context, int resource, ViewGroup root) {
LayoutInflater factory = LayoutInflater.from(context);
return factory.inflate(resource, root);
}
因此,在内部,View
类的inflate()
方法使用LayoutInflater
,这让我假设两者没有区别。
发布于 2015-04-02 19:51:07
我只是从中得到了一个问题。这就是我的发现。
父级使用LayoutInflator.inflate(id,View.inflate )。如果Viewparent参数为空,它将忽略父对象的layoutparam。
但。Inflator.inflate还有另一个接口inflate(id,View parent,boolean attach)。当您需要使用父级layoutparamter初始化此视图时,此方法非常有用
https://stackoverflow.com/questions/23908985
复制相似问题