2

スクロール ビューのテーブル レイアウトがあります。2 つの列があります。そのうちの 1 つ (最初) は説明で、2 つ目は金額です。必要に応じて、最初の列がテキストをラップできるようにしました。私の問題は、両方の列の幅を制限して、画面内で 50-50% になるようにすることです。最初の列は折り返す必要があります。私は android:minWidth="215dp" を使用しようとしましたが、xml に値をハードコーディングしたくありません。

ここにxmlがあります。どんな助けでも大歓迎です。

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/footer"
    android:layout_below="@+id/tableheader"
    android:fillViewport="true"
    android:scrollbars="none" >

    <TableLayout
        android:id="@+id/dataTable"
        style="@style/SummaryTableLayout" >

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

        <TextView
            android:gravity="left"
            android:minWidth="215dp"
            />

        <TextView
            android:gravity="left"
            android:minWidth="215dp"
                    />

        </TableRow>
    </TableLayout>
</ScrollView>

SummaryTableLayout Style 部分は

<style name="SummaryTableLayout" >
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:stretchColumns">0</item>
    <item name="android:shrinkColumns">0</item>
    <item name="android:layout_marginTop">10dp</item>
    <item name="android:layout_marginBottom">25dp</item>
    <item name="android:scrollbars">vertical</item>
    <item name="android:isScrollContainer">true</item>
    <item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
</style>

編集 ::: これは私の xml の 1 つです。テーブル レイアウトに 4 つの列がある 2 番目の xml があります。最初の列に WRAPPING を使用して、それらを等間隔に配置したいと考えています。

4

1 に答える 1

1

属性を使用しlayout_weigthます。これはあなたのために働くはずです:

<TableLayout
    android:id="@+id/dataTable"
    style="@style/SummaryTableLayout" >

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

    <TextView
        android:gravity="left"
        android:width="0px"
        android:layout_weight="0.5"/>

    <TextView
        android:gravity="left"
        android:width="0px"
        android:layout_weight="0.5"/>

    </TableRow>
</TableLayout>

ここでこの答えに従って。layout_weight列の割合を定義するために使用されます。

編集この場合に使用する正しい属性であると思われるため、列の代わりlayout_widthに使用したことに注意してください。width

于 2013-02-23T10:21:58.470 に答える