【问题标题】:RelativeLayout, align left/right for two buttons, align center for one相对布局,左/右对齐两个按钮,居中对齐一个
【发布时间】:2016-07-31 10:59:11
【问题描述】:

我使用 RelativeLayout 来显示一个或两个按钮。对于两个按钮的情况,它们需要左右对齐,对于一个按钮的情况,它需要居中。

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

我将关闭按钮更改为 View.GONE 用于一个按钮的情况,但操作按钮仍向左对齐 - 是否有任何非编程方式将其居中对齐?

【问题讨论】:

  • 你能发布完整的xml

标签: android layout android-relativelayout


【解决方案1】:
<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>

【讨论】:

  • 谢谢!我使用 wrap_content 作为宽度,它也有效
猜你喜欢
  • 1970-01-01
  • 2021-08-25
  • 2013-08-07
  • 2016-03-26
  • 1970-01-01
  • 1970-01-01
  • 2019-01-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多