簡體   English   中英

RelativeLayout,左右對齊兩個按鈕,中間對齊一個按鈕

[英]RelativeLayout, align left/right for two buttons, align center for one

我正在使用RelativeLayout顯示一個按鈕或兩個按鈕。 對於兩個按鈕盒,它們需要左/右對齊,對於一個按鈕盒,它需要居中。

<RelativeLayout>
  <Button
    android:id="@+id/action"
    android:layout_alignParentLeft="true"/>
  <Button
    android:id="@+id/dismiss"
    android:layout_alignParentRight="true"/>
</RelativeLayout>

我將一個按鈕的情況下的關閉按鈕更改為View.GONE ,但操作按鈕仍然向左對齊-是否有任何非編程方式將其居中對齊?

<LinearLayout
  android:orientation="horizontal">
  <Button
    android:id="@+id/action"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"/>
  <Button
    android:id="@+id/dismiss"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1" />
</LinearLayout>

暫無
暫無

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

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