Source code to get an Android TableRow to align elements right

As a quick note, if you need to get an Android TableRow to align right, I can confirm that this layout code works:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:stretchColumns="1">

    <TableRow android:layout_width="fill_parent">
        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:entries="@array/playerRatingArray"
            android:layout_column="1"
            android:layout_gravity="right"
            android:padding="10dip"
            />
        <Spinner
            android:id="@+id/spinner2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:entries="@array/playerRatingArray"
            android:layout_column="2"
            android:layout_gravity="right"
            android:padding="10dip"
            />
        <Spinner
            android:id="@+id/spinner3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:entries="@array/playerRatingArray"
            android:layout_column="3"
            android:layout_gravity="right"
            android:padding="10dip"
            />
    </TableRow>
</TableLayout>

The keys were defining the TableRow like this:

<TableRow android:layout_width="fill_parent">

and then setting android:layout_gravity="right" for each of the elements in the TableRow.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.