Align ImageView to the right

Showing 1-2 of 2 messages
Align ImageView to the right Rodrigo Chiossi 3/22/10 10:30 AM
Hi there!
I'm new to android and I'm trying to create a simple layout, with a
TextView aligned to the left and an ImageView aligned to the right,
both in the same line.
I've tried many approaches, but the Imageview never aligns to the
right. Here is my latest attempt:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TableRow>
        <TextView android:text="@string/label_dots"
            android:id="@+id/TextView01"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:gravity="left"/>
        <ImageView android:id="@+id/ImageView01"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/action_add"
            android:gravity="right"/>
    </TableRow>
</TableLayout>

It doesn't work on eclipse Layout preview and it doesn't work on my
G1.
Any ideas how to fix it?

Re: Align ImageView to the right a2ronus 3/30/10 2:23 AM
Have you tried the RelativeLayout yet?

Here's an example:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#0000FF"
>
                <TextView
                        android:text="left"

                        android:id="@+id/TextView01"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:background="#00FF00"

                />
                <ImageView android:id="@+id/ImageView01"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/icon"
                        android:gravity="right"
                        android:layout_alignParentRight="true"
                        android:background="#FFFF00"
                />
</RelativeLayout>