LinearLayout布局下android:layout_weight用法
layout_weight意思是布局比重的意思,在線性布局中常用layout_weight,分割布局。
通常線性布局中寬高布局常用android:layout_width=match_parent|wrap_content,android_height=match_parent|wrap_content來進(jìn)行布局,如果要用比重布局,通常android:layout_width屬性就會不起作用,設(shè)置為"0";根據(jù)想要布局的比例,設(shè)定android:layout_weight的值,值越大,占的布局就越大。
考慮到Android多版本的兼容問題,通常使用match_parent而不使用fill_parent.
android 中,布局文件可不可以設(shè)置layout_weight
為什么android layout_weight屬性可以把控件按一定的比例進(jìn)行布局
下Layout_weight屬性的作用:它是用來分配屬于空間的一個屬性,你可以設(shè)置他的權(quán)重。
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.
重點(diǎn)有兩個
layout_weight表示LinearLayout中額外空間的劃分(可能擴(kuò)大應(yīng)用layout_weight前的大小也可能縮小)。
按比例(layout_weight大小的比例)。
以下說的都以android:orientation="horizontal" 為例
看了一下源碼,雖說不太懂,但了解了下大概意思,按照自己的理解總結(jié)一下,直接寫一下簡化的代碼吧(下面的代碼是LinearLayout源文件中一部分的精簡,變量名稱含義可能不準(zhǔn)確,為敘述方便暫作此解釋):
android編程android:layout_weight="1"報錯“Invalid layout param in a RelativeLayout: layout_weight
本文發(fā)布于:2023-02-28 19:41:00,感謝您對本站的認(rèn)可!
本文鏈接:http://m.newhan.cn/zhishi/a/167762850766090.html
版權(quán)聲明:本站內(nèi)容均來自互聯(lián)網(wǎng),僅供演示用,請勿用于商業(yè)和其他非法用途。如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除。
本文word下載地址:layoutweight.doc
本文 PDF 下載地址:layoutweight.pdf
| 留言與評論(共有 0 條評論) |