gpt4 book ai didi

Android : What is the difference between View. 膨胀和 getLayoutInflater().膨胀?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:25:14 25 4
gpt4 key购买 nike

什么是真正的区别:

return context.getLayoutInflater().inflate(R.layout.my_layout, null);

Inflate a new view hierarchy from the specified xml resource.

return View.inflate(context, R.layout.my_layout, null);

Inflate a view from an XML resource. This convenience method wraps the LayoutInflater class, which provides a full range of options for view inflation.

最佳答案

两者是一样的。第二个版本只是完成任务的一种方便而简短的方法。如果您查看 View.inflate() 方法的源代码,您会发现:

 /**
* Inflate a view from an XML resource. This convenience method wraps the {@link
* LayoutInflater} class, which provides a full range of options for view inflation.
*
* @param context The Context object for your activity or application.
* @param resource The resource ID to inflate
* @param root A view group that will be the parent. Used to properly inflate the
* layout_* parameters.
* @see LayoutInflater
*/
public static View inflate(Context context, int resource, ViewGroup root) {
LayoutInflater factory = LayoutInflater.from(context);
return factory.inflate(resource, root);
}

实际上在后端做同样的工作,你提到的第一种方法。

关于Android : What is the difference between View. 膨胀和 getLayoutInflater().膨胀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35548844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com