【发布时间】:2015-02-27 22:40:07
【问题描述】:
如果第 3 列有大文本,第 2 列会消失。如果我设置android:stretchColumns="2,3",第 2 列也会消失。我想将minWidths 设置为第 2 列。但是这个属性被忽略了。
我现在正在通过设置 android:stretchColumns="3" 和 android:shrinkColumns="3" 并将 maxWidth 应用到位置 2 上的 TextView 来帮助自己。这几乎可以完成工作,但 minWidth 将是更多的解决方案。
<TableLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:shrinkColumns="2,3"
android:stretchColumns="3" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextViewIdLabel"
style="@style/overlay_content"
android:text="@string/id_label"
android:textStyle="bold" />
<TextView
android:id="@+id/TextViewIdValue"
style="@style/overlay_content"
android:layout_marginLeft="4dp" />
<TextView
android:id="@+id/TextViewPersonIdLabel"
style="@style/overlay_content"
android:layout_marginLeft="8dp"
android:text="@string/person_id_label"
android:textStyle="bold" />
<TextView
android:id="@+id/TextViewPersonIdValue"
style="@style/overlay_content"
android:layout_marginLeft="4dp" />
</TableRow>
<!-- I skipped the other rows -->
</TableLayout>
如果您想知道,这是使用的样式:
<style name="overlay_content">
<item name="android:textColor">@color/foreground_color_on_dark_background</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">20sp</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
</style>
更新:
随着答案的出现,我发现了更多关于我在此评论中总结的要求:How to shrink a TableLayout column to a minWidth?
【问题讨论】:
-
如何设置每列的权重而不是
android:shrinkColumns和android:stretchColumns。那么对于第 1 列,您可以设置 0.2 的权重,第 2 列的 0.3 和第 3 列的 0.5 等等? -
@Slartibartfast 到目前为止,您的解决方案是唯一始终确保至少部分显示所有列的解决方法。
标签: android tablelayout