View.inflate与LayoutInflater [英] View.inflate vs LayoutInflater

查看:56
本文介绍了View.inflate与LayoutInflater的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 LayoutInflater 和静态方法 View.inflate()的主要区别是什么?使用它们中的任何一个是否有缺点,或者它们的用途不同?

What is the main difference in using LayoutInflater and static method View.inflate()? Are there any drawbacks in using any of them or maybe they serve different purposes?

推荐答案

如果查看 View.inflate()的源代码,我们将看到以下内容:

If looking at the source of View.inflate() we see this:

public static View inflate(Context context, int resource, ViewGroup root) {
        LayoutInflater factory = LayoutInflater.from(context);
        return factory.inflate(resource, root);
}

因此,在内部, View 类的 inflate()方法使用了 LayoutInflater ,这使我认为没有区别.

So, internally, the inflate() method of View class uses the LayoutInflater, which makes me assume there's no difference.

这篇关于View.inflate与LayoutInflater的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆