Reputation: 2531
How can buttons be aligned in android so that they have proper spacing above, below, and between buttons?
Current code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<include
android:id="@+id/ActionBackupBar"
layout="@layout/actionbar_layout"
/>
<Button
android:id="@+id/btnSelectLocation"
style="@style/ButtonText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_marginRight="2sp"
android:layout_marginTop="0sp"
android:text="@string/activitySelectMyLocationButton" />
<Button
android:id="@+id/btnCurrentLocation"
style="@style/ButtonText"
android:text="@string/activitySelectSearchLocationButton"
android:layout_marginBottom="5sp"
android:layout_marginLeft="5sp"
android:layout_marginRight="2sp"
/>
Upvotes: 0
Views: 70
Reputation: 117
Change for RelativeLayout and after try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="@+id/btnSelectLocation"
style="@style/ButtonText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="text1" />
<Button
android:id="@+id/btnCurrentLocation"
style="@style/ButtonText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/btnSelectLocation"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="test2" />
</RelativeLayout>
Upvotes: 1
Reputation: 534
Use RelativeLayout instead of LinearLayout. Then you can easily align the buttons.
Hope this can help you.
Upvotes: 0