【发布时间】:2011-06-22 11:23:11
【问题描述】:
我在 ListView 中使用 TableLayout。我呈现的数据本质上是表格的,TableLayout 似乎是确保列按需要排列的好方法。这种方法在大多数情况下都很有效 - 见下文。
但有时代表列的视图会包裹它们的文本内容,如下所示。
搜索了一会后,我发现了following discussion on the Android Google Group。作为回应,我在 TableLayout 中设置了android:stretchColumns="*",瞧,包含的 TextView 停止了神秘地包装它们的文本。
这是布局 XML 的部分内容,其中的更改用注释突出显示:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*"> <!-- stretchColumns needed to prevent
TableLayout from unilaterally deciding to shrink the column
width and thereby causing text to wrap. -->
虽然我现在得到了想要的结果,但我有点困惑为什么这会“解决”我的问题。 TableLayout documentation 声明“列的宽度由该列中单元格最宽的行定义。”但如果这是真的,为什么一开始列明显缩小导致文本换行?
谁有好的解释?
【问题讨论】:
标签: android text tablelayout android-tablet-layout