2

我有一个滚动视图表格布局。它有 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 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 之一。我有第二个 xml,其中表格布局有 4 列,我希望它们的间距也均匀,第一列有 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_widthwidth列替换,因为这似乎是在这种情况下使用的正确属性。

于 2013-02-23T10:21:58.470 回答