2011-11-07 25 views
0

在我的應用程序屏幕中,我有兩個按鈕。一個是激活,另一個是關於。我想在左側激活,在右側激活並且尺寸相同。我寫下面的代碼:如何在android的兩側佈置兩個按鈕?

<LinearLayout 
    android:id="@+id/layout2" 
    android:layout_width="fill_parent" 
    android:layout_height="60px" 
    android:layout_alignParentBottom="true" 
    android:background="@drawable/bottom_bar" 
> 
<Button 
    android:id="@+id/btnActivate" 
    android:layout_width="0dp" 
    android:layout_height="40px" 
    android:layout_marginTop="10px" 
    android:layout_weight="1.0" 
    android:text="Activate" 
    android:textColor="#000000" 
> 
</Button> 
<Button 
    android:id="@+id/btnAbout" 
    android:layout_weight="1.0" 
    android:layout_width="0dp" 
    android:layout_height="40px" 
    android:layout_marginTop="10px" 
    android:text="About" 
    android:textColor="#000000" 
> 
</Button> 
</LinearLayout> 

現在這兩個按鈕都來了相同的大小。但我希望它們具有60dp的特定寬度。我怎樣才能做到這一點??

在此先感謝。

+0

你已經在你的寬度屬性上設置了0dp。您的按鈕不會以這種方式顯示。 – hovanessyan

回答

0

通過將兩個按鈕的android:layout_weight設置爲1,可以讓按鈕展開並以相同的寬度(重量)覆蓋整個佈局寬度。

刪除android:layout_weight屬性並將android:layout_width設置爲所需的寬度。

+0

是的..我刪除了。並使用android:layout_alignParentRight和android:layout_alignParentLeft我解決了這個問題。 –

相關問題