LayoutInflate.inflate(int resourceId, ViewGroup root, boolean attachToRoot)三个参数含义:

首先明白下面知识点:

给控件所指定的layout_width和layout_height到底是什么意思?该属性的表示一个控件在容器中的大小,就是说这个控件必须在容器中,这个属性才有意义,否则无意义。

 

当:root == null,无论attachToRoot 是否ture还是false

ResourceId的根节点没有依赖的父布局(容器),所以width和height属性失效

 

当:root != null,如果attachToRoot = ture;

则将resourceId对应得布局加载到root中,并将root返回;resourceId中的width和height属性有效

当:root != null,如果attachToRoot = false;

则将resourceId对应的view设置容器为root,但是不添加到root中,resourceId中的width和height属性有效

 

相关文章:

  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2021-12-19
  • 2021-08-08
  • 2021-09-03
猜你喜欢
  • 2022-01-11
  • 2022-12-23
  • 2021-06-17
  • 2021-09-17
  • 2021-09-21
  • 2022-01-28
  • 2021-12-19
相关资源
相似解决方案