Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: TableLayout align first column right, second left

What must I do to get something like that:

Image sample

I can do it without problems in HTML but how in Android?

like image 518
Dario Rossi Avatar asked Jul 19 '13 10:07

Dario Rossi


1 Answers

Write first TextView wight=1 and second TextView wight=2


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="right"
                android:text="key" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:gravity="left"
                android:text="value" />
        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="right"
                android:text="More key" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:gravity="left"
                android:text="More value" />
        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="right"
                android:text="Even more key" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:gravity="left"
                android:text="Even more value" />
        </TableRow>
    </TableLayout>

</LinearLayout>
like image 167
Venky Avatar answered Nov 13 '22 05:11

Venky