LinearLayout布局下android:layout_weight用法
layout_weight意思是布局比重的意思,在线性布局中常用layout_weight,分割布局。
通常线性布局中宽高布局常用android:layout_width=match_parent|wrap_content,android_height=match_parent|wrap_content来进行布局,如果要用比重布局,通常android:layout_width属性就会不起作用,设置为"0";根据想要布局的比例,设定android:layout_weight的值,值越大,占的布局就越大。
考虑到Android多版本的兼容问题,通常使用match_parent而不使用fill_parent.
android 中,布局文件可不可以设置layout_weight
为什么android layout_weight属性可以把控件按一定的比例进行布局
下Layout_weight属性的作用:它是用来分配属于空间的一个属性,你可以设置他的权重。
SDK中的解释:
Indicates how much of theextra spacein the LinearLayout will be allocated to the view associated with the LayoutParams. Specify 0 if the view should not be stretched. Otherwi the extra pixels will bepro-ratedamong all views who weight is greater than 0.
重点有两个
layout_weight表示LinearLayout中额外空间的划分(可能扩大应用layout_weight前的大小也可能缩小)。
按比例(layout_weight大小的比例)。
以下说的都以android:orientation="horizontal" 为例
看了一下源码,虽说不太懂,但了解了下大概意思,按照自己的理解总结一下,直接写一下简化的代码吧(下面的代码是LinearLayout源文件中一部分的精简,变量名称含义可能不准确,为叙述方便暂作此解释):
android编程android:layout_weight="1"报错“Invalid layout param in a RelativeLayout: layout_weight
本文发布于:2023-02-28 19:41:00,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/zhishi/a/167762850766090.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:layoutweight.doc
本文 PDF 下载地址:layoutweight.pdf
| 留言与评论(共有 0 条评论) |