ZAJ
ZAJ

Reputation: 835

TableLayout issue

I have this table layout which has 2 rows on first two line and I have a row on the third line(customerAddress) which I want to be right aligned and take all the space. How can I achieve this. I tried gravity = right but no luck.

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

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*" >

    <TableRow>

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/customerCode" />

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/customerName" />
    </TableRow>
    <TableRow>

       <TextView
            android:id="@+id/customerCode"
            style="@style/CustomerTextView"
            android:gravity="right" />

        <TextView
            android:id="@+id/customerName"
            style="@style/CustomerTextView"
            android:gravity="right" />
    </TableRow>

    <TableRow>

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/customerAddress" />
    </TableRow>
     <TableRow>

        <TextView
            android:id="@+id/customerAddress"
            style="@style/CustomerTextView"
            android:gravity="right" />
    </TableRow>

    <TableRow>

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/OrganizationName" />

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/POBox" />
    </TableRow>

    <TableRow>

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/phone" />

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/fax" />
    </TableRow>
</TableLayout>

Upvotes: 0

Views: 288

Answers (2)

ZAJ
ZAJ

Reputation: 835

Ok, got it to work. For those who might stumble to this issue the code i have added below

 <TableRow
        android:gravity="right" >


        <TextView
            android:id="@+id/customerAddress"
            style="@style/CustomerTextView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:gravity="right" />

    </TableRow>

Upvotes: 2

D-32
D-32

Reputation: 3255

Try adding android:layout_span="2" to that TableRow.

<TableRow
    android:layout_span="2"
>
    <TextView
        style="@style/CustomerLabelTextView"
        android:gravity="right"
        android:text="@string/customerAddress"
    />
</TableRow>

http://developer.android.com/reference/android/widget/TableRow.LayoutParams.html#attr_android:layout_span

Upvotes: 0

Related Questions