2012-03-18 65 views
1

我需要爲屏幕上的按鈕設置相同的尺寸。這些按鈕有不同的內容(不同的長度)。我希望它看起來像3號線在畫面LinearLayout組件大小。重量如何影響尺寸

enter image description here

我想:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/LinearLayout1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:orientation="horizontal" > 

<Button 
    android:id="@+id/button2" 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:text="Button" /> 


<Button 
    android:id="@+id/button1" 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:text="B" /> 

但我得到了兩個不同大小的小按鈕在屏幕的中心。哪裏不對? 請舉個例子。

回答

0

嘗試改變在的LinearLayout部寬度PARAM到

android:layout_width="fill_parent" 
+0

謝謝。有用。請你解釋一下嗎? – user1277317 2012-03-18 20:02:18

0

添加android:weightsum=10LinearLayout和分配你部分以可以是2,4,4。你也可以通過使用Fast View(在eclipse左下角的小方塊) - >Other - >Properties,通過百分比(20%,40%,40%)來調整它們並在開發時輸入值。

+0

謝謝你的作品,但只有當我添加在LinearLayout android:layout_width =「fill_parent」 像rahul寫道 – user1277317 2012-03-18 20:10:06

+0

尼斯。作爲用戶,如果您發現答案完全有用,您應該通過打勾檢查來接受,或者在部分有用的情況下取消提示。 – jmishra 2012-03-18 20:11:58