簡體   English   中英

如何在Android的兩側布置兩個按鈕?

[英]How to lay out two button in two side in 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>

現在,兩個按鈕的尺寸都相同。 但是我希望它們具有一些特定的寬度,例如60 dp。 我怎樣才能做到這一點??

提前致謝。

通過將兩個按鈕的android:layout_weight設置為1,您要求按鈕展開並覆蓋具有相等寬度(權重)的布局的整個寬度。

移除android:layout_weight屬性,並將android:layout_width設置為所需寬度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM