代码之家  ›  专栏  ›  技术社区  ›  Bart Friederichs

如何在TableRow中“锁定”宽度

  •  0
  • Bart Friederichs  · 技术社区  · 7 年前

    我有这样(部分)的布局:

    <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 textView3 越来越小,直到里面的文本被裁剪,或者如果 maxLines 未设置。

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

    正在添加 ellipsize tvLocation

    2 回复  |  直到 7 年前
        1
  •  0
  •   Deng    7 年前

    通过设置android:layout\u width=“0dp”,将textView3和tvLocation的宽度设置为零。

        2
  •  0
  •   Zahid    7 年前

    在视图中使用布局权重时,将其高度或宽度更改为 0dp 取决于其方向。因为在使用权重时,会忽略其他属性。

    在这里,视图水平对齐,因为它位于表行中,因此更改 android:layout_width 0dp