tags:

views:

24

answers:

4

I defined a LinearLayout:

<LinearLayout
    android:id="@+id/top_menu"
    android:layout_width="fill_parent"
    android:orientation="horizontal"
    android:background="@drawable/backrepeat"
    android:layout_height="wrap_content" >

        <ImageView
        android:id="@+id/topLeft"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="left"
        android:src="@drawable/library_top_left">
        </ImageView>


        <ImageView
        android:id="@+id/topMiddle"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/library_top_middle"/>

        <ImageView
        android:id="@+id/topRight"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="right"
        android:src="@drawable/library_top_right"/>

    </LinearLayout>

I'd like that one image is on the left side of the screen, one in the middle, and one on the right side. However all of them are on the left side. How can I fix that?

A: 

Do you want them spaced ?

fedj
What's spaced? ?
Roflcoptr
You want the images spaced one from another ?
fedj
yes that would be the goal
Roflcoptr
Take a look to RelativeLayout, layout_alignParentLeft, alignParentRight and alignCenterHorizontal layout params
fedj
+1  A: 

Put in android:layout_weight="1" into each of the image views. Supply padding/margin to make it better.

Sameer Segal
it looks better now, but however, the images are not really on the right corner but some pixels away from the border.
Roflcoptr
The pics will be streched and I don't think it is the goal here
fedj
+1  A: 

Try a relative layout, and instead of gravity, try android:layout_alignParentLeft=true, android:layout_centerInParent=true, android:layout_alignParentRight=true

<RelativeLayout
android:id="@+id/top_menu"
android:layout_width="fill_parent"
android:background="@drawable/backrepeat"
android:layout_height="wrap_content" >

    <ImageView
    android:id="@+id/topLeft"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_alignParentLeft="true"
    android:src="@drawable/library_top_left"/>

    <ImageView
    android:id="@+id/topMiddle"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_centerInParent="true"
    android:src="@drawable/library_top_middle"/>

    <ImageView
    android:id="@+id/topRight"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@drawable/library_top_right"/>

</RelativeLayout>
magicman
this works. thanks.
Roflcoptr
A: 

Take a look at RelativeLayout.

JRL