RelativeLayout,两个按钮对齐 left/right,一个居中对齐
RelativeLayout, align left/right for two buttons, align center for one
我正在使用 RelativeLayout 来显示一个按钮或两个按钮。对于两个按钮的情况,它们需要 left/right 对齐,对于一个按钮的情况,它需要居中。
<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>
我正在使用 RelativeLayout 来显示一个按钮或两个按钮。对于两个按钮的情况,它们需要 left/right 对齐,对于一个按钮的情况,它需要居中。
<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>