有的時候我們開發(fā)一個產(chǎn)品的時候需要讓其中某個控件的寬度或高度占據(jù)其父容器的寬度或高度的一半顯示,這個時候由于設(shè)備尺寸的限制,做到在每個設(shè)備上都具有同樣的效果的話,我們就需要用到weightSum屬性和layout_weight屬性。
具體的實(shí)現(xiàn)過程分析如下:
首先為父容器指定一個weightSum,然后為其子控件的layout_weight屬性值設(shè)為weightSum的一半,這個時候,就實(shí)現(xiàn)了占據(jù)其一半的效果。
1
<
LinearLayout
xmlns:android
="http://schemas.android.com/apk/res/android"
2
android:layout_width
="fill_parent"
3
android:layout_height
="fill_parent"
4
android:background
="#ffffff"
5
android:gravity
="center"
6
android:orientation
="horizontal"
7
android:weightSum
="1"
>
8
9
<
Button
10
android:layout_width
="0dp"
11
android:layout_height
="wrap_content"
12
android:layout_weight
="0.5"
13
android:text
="@string/activity_main_click_me"
/>
14
15
</
LinearLayout
>
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

