[英]RelativeLayout, align left/right for two buttons, align center for one
I'm using RelativeLayout for displaying one button or two buttons. 我正在使用RelativeLayout显示一个按钮或两个按钮。 For the two buttons case, they need to be left/right aligned, for one button case, it needs to be centered.
对于两个按钮盒,它们需要左/右对齐,对于一个按钮盒,它需要居中。
<RelativeLayout>
<Button
android:id="@+id/action"
android:layout_alignParentLeft="true"/>
<Button
android:id="@+id/dismiss"
android:layout_alignParentRight="true"/>
</RelativeLayout>
I changed the dismiss button to View.GONE
for one button case, but action button still aligns to left - Are there any non-programmatical way to align it center? 我将一个按钮的情况下的关闭按钮更改为
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.