0

我有这个表格布局,前两行有 2 行,第三行有一行(customerAddress),我想右对齐并占用所有空间。我怎样才能做到这一点。我试过gravity = right但没有运气。

<?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>

4

2 回答 2

2

好的,让它工作。对于那些可能偶然发现这个问题的人,我在下面添加了代码

 <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>
于 2012-09-18T09:26:51.507 回答
0

尝试将 android:layout_span="2" 添加到该 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

于 2012-09-18T07:22:10.023 回答