I'm using RelativeLayout for displaying one button or two buttons. 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?
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.