个人经验 - Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑

编程知识 更新时间:2023-04-05 07:05:05

Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑:

此坑出现的条件:

1.RelativeLayout布局的layout_height属性设置为wrap_content

2.某“居中View”设置为layout_centerX(layout_centerVertical、layout_centerHorizontal、layout_centerInParent)

3.其它View相对于“居中View”做布局

此时坑出现了:

无论其它View设置了在“居中View”的下方(layout_below、layout_below)、上方(layout_above)、底部对齐(layout_alignBottom)等等,通通无效!

 

填坑方案:

RelativeLayout布局的layout_height属性设置为match_parent即可!

即使外层有LinearLayout使用layout_weight平分空间,它的match_parent也不会撑大外层LinearLayout的空间的。

当初想设置wrap_content,其实就是怕内部的RelativeLayout设置match_parent后会被撑大而已,实践证明,多虑了!

转载于:https://wwwblogs/AsionTang/p/4029446.html

更多推荐

个人经验 - Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑

本文发布于:2023-04-05 07:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/c2d9d475a53776052debcf7665108aee.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   布局   属性   经验   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 45442文章数
  • 14阅读数
  • 0评论数