inflate的使用

作用:将xml文件中的布局转化成view视图

一. 三个参数

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

 

 

1. root 不为null ,attachToRoot为true

inflate(R.layout.linerlayout,main,ture);

直接把R.layout.linerlayout的布局添加到main的view中,相当于内嵌

 

 

2. root不为null ,attachToRoot为false

不把R.layout.linerlayout的布局添加到main中,目的:为了创建view

并且让其处在某一容器中,此时根节点的layout_width和layout_height才有效

如果要使用需要手动添加 view.add();

3. root为null

此时attachToRoot 的值无效(效果一样)。linerlayout没有处于某一个容器中,所以它的根节点

layout_width和layout_height会失效

 

二. 两个参数

 

  1. public View inflate(XmlPullParser parser, @Nullable ViewGroup root) {  
  2.         return inflate(parser, root, root != null);  
  3.     }  

当 root 不为 null 时:

      相当于 inflate(parser,root,ture);    //只是为了将该xml布局文件转化为它对应的View对象方便下面对该item的操作

当root为null时:

      相当于 inflate(parser,null,flase);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值