I have a linearlayout with two linearlayouts inside. Both linearlayouts have 2 buttons. I want to align the first two buttons to the left, and the other two buttons to the right. Unfortunately I have the four buttons (or the 2 layouts) side by side.
This is my code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="@drawable/vat_header_selector"
android:orientation="horizontal" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_numbers"
android:layout_width="90dp"
android:layout_height="30dp"
android:textColor="@drawable/vat_btn_header_textcolor_selector"
android:background="@drawable/vat_btn_header_selector"
android:text="Numbers">
</Button>
<Button
android:id="@+id/btn_text"
android:layout_width="90dp"
android:layout_height="30dp"
android:textColor="@drawable/vat_btn_header_textcolor_selector"
android:background="@drawable/vat_btn_header_selector2"
android:text="Words">
</Button>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_black"
android:layout_width="50dp"
android:layout_height="30dp"
android:textColor="@drawable/vat_btn_header_textcolor_selector"
android:background="@drawable/vat_btn_header_selector"
android:text="B">
</Button>
<Button
android:id="@+id/btn_white"
android:layout_width="50dp"
android:layout_height="30dp"
android:textColor="@drawable/vat_btn_header_textcolor_selector"
android:background="@drawable/vat_btn_header_selector2"
android:text="W">
</Button>
</LinearLayout>
</LinearLayout>
This is how it looks like:
And this is what I want:
Gravity left
, right
doesn't work when the orientation of the LinearLayout
is set to horizontal(as the views are placed along the X axis). One way to do what you want is to insert an empty View
between the two LinearLayouts
to create a space between them:
<View android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With