Joe C
Joe C

Reputation: 2834

XML: layout_gravity ="right" not working for a TextView within a TableRow

Sorry for all the folks who use gravity instead of layout_gravity or who don't make the parent view wide enough. I'm not making either of those mistakes yet textView1 is pushed all the way to the left of the row and textView2 is push right up against that. As far as I know testView2 should be anchored to the right of the row, which is really the right of the entire screen.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TableLayout
        android:id="@+id/hwTable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="HW Part"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Make / Model"
                android:layout_gravity="right"
                android:textAppearance="?android:attr/textAppearanceMedium" />

        </TableRow>

    </TableLayout>

    <Button
        android:id="@+id/vitalsDone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Back" />

</LinearLayout>

Upvotes: 1

Views: 1246

Answers (1)

Some guy
Some guy

Reputation: 71

You probably found it out already, But if anyone else reads it...

Add android:stretchColumns="1" to the table Layout.

Upvotes: 7

Related Questions