2011-07-23 58 views
0

我有以下問題:如何正確設置Android中LinearLayer的按鈕大小?

我有一個水平LinearLayout有兩個按鈕,確定和取消。我想要按鈕填充父寬度,我的意思是每個按鈕50%(如果我有3個按鈕33%每個),按鈕必須具有相同的寬度,但當我選擇「填充父母」在確定按鈕它填滿一切,並取消按鈕不再可見。

您的幫助表示讚賞。非常感謝您

回答

2

上的XML佈局這個標籤添加到每個按鈕:

android:layout_weight="1" 

,並設置widht爲0px

+0

組0像素到按鈕寬度或按鈕layout_width屬性? –

0

使用weightSumlayout_weight屬性來創建所需的視圖按鈕。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" 
    android:weightSum="2"> 

    <Button android:text="Ok" android:id="@+id/button1" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="1" /> 
    <Button android:text="Cancel" android:id="@+id/button2" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="1" /> 

</LinearLayout> 

在三個按鈕weightSum情況下是3

+0

非常感謝你,請投票我想達到投票所需的最低聲望的問題 – BlackBishop