public View inflate (int resource, ViewGroup root, boolean attachToRoot)中 attachToRoot 参数 的理解

官方解释

inflate
added in API level 1

public View inflate (int resource,
ViewGroup root,
boolean attachToRoot)

Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.

Parameters
resource int: ID for an XML layout resource to load (e.g., R.layout.main_page)

root ViewGroup: Optional view to be the parent of the generated hierarchy (if attachToRoot is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToRoot is false.)

This value may be null.
attachToRoot boolean: Whether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML.

Returns
View The root View of the inflated hierarchy. If root was supplied and attachToRoot is true, this is root;

其它诠释
一、
https://stackoverflow.com/questions/22326314/what-is-the-use-of-attach-to-root-in-layout-inflater

attachToRoot:

attaches the views to their parent (includes them in the parent hierarchy), so any touch event that the views recieve will also be transfered to parent view. Now it’s upto the parent whether it wants to entertain those events or ignore them. if set to false, they are not added as direct children of the parent and the parent doesn’t recieve any touch events from the views.

二、
https://stackoverflow.com/questions/12567578/what-does-the-layoutinflater-attachtoroot-parameter-mean/45809756#45809756
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值