I want to align 3 objects horizontally in android layout, where the first object must align left and the third must appear right and the second object have to get the rest width in the center.
How can I make that ?
I want to align 3 objects horizontally in android layout, where the first object must align left and the third must appear right and the second object have to get the rest width in the center.
How can I make that ?
This is pretty much what you want. All you have to do is replace the TextView with the views you want. I made the backgrounds red, because it's Christmas.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:background="#f00"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" android:background="#f00"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="TextView" android:background="#f00"/>
</LinearLayout>
You need a linear layout with horizontal orientation. After that declare your three objects and give them a weight of 1 each: android:layout_weight="1"