如何 "lock" TableRow 的宽度

How to "lock" width in a TableRow

我有这个(部分)布局:

<TableRow
    android:id="@+id/trLocation"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/location"/>

    <TextView android:layout_width="wrap_content"
              android:textSize="50dp"
              android:layout_height="wrap_content"
              android:text="1234"
              android:id="@+id/tvLocation"
              android:layout_weight="1"
        />
</TableRow>

现在,当我将 tvLovation 中的数据设置得太长时,它会 "push" 和 textView3 越来越小,直到里面的文本甚至被裁剪或流向如果未设置 maxLines,则为下一行。

如何确保第一列的宽度永远不会小于我最长的文本?

ellipsize 添加到 tvLocation 没有效果。

通过设置 android:layout_width="0dp".

将 textView3 和 tvLocation 的宽度设置为零

当您在视图中使用布局粗细时,请根据其方向将其高度或宽度更改为 0dp。因为在使用权重时,其他属性被忽略了。

这里的视图水平对齐,因为它在 table 行中,因此将 android:layout_width 更改为 0dp