gpt4 book ai didi

android - 如何将 TableLayout 列缩小到 minWidth?

转载 作者:太空宇宙 更新时间:2023-11-03 13:20:50 26 4
gpt4 key购买 nike

如果第 3 列有大文本,第 2 列就会消失。如果我设置 android:stretchColumns="2,3",第 2 列也会消失。我想将 minWidth 设置为第 2 列。但是这个属性被忽略了。

我现在通过设置 android:stretchColumns="3"android:shrinkColumns="3" 并应用 maxWidth 来帮助自己code> 到位置 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:shrinkColumnsandroid:stretchColumns 。因此,对于第 1 列,您可以设置 0.2 权重,第 2 列为 0.3,第 3 列为 0.5,依此类推

关于android - 如何将 TableLayout 列缩小到 minWidth?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27939067/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com