1

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 ?

Adham
  • 63,550
  • 98
  • 229
  • 344
  • 1
    Because your question shows no research effort. This is basic Android stuff, documented pretty much everywhere. –  Dec 27 '11 at 22:01
  • 2
    Use relative layout and gravity on your left and right objects. – Aleks G Dec 27 '11 at 22:02

3 Answers3

7

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>
Boude
  • 677
  • 6
  • 13
1

This is the example that you are looking for. Change the textview for a Linearlayout that content the object that you want. If dont know how to put the object, check This reference looking for the ID method to put code.

vgonisanz
  • 11,831
  • 13
  • 78
  • 130
1

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"

Linear Layout and weight in Android

Community
  • 1
  • 1
barry
  • 4,037
  • 6
  • 41
  • 68