2017-10-11 57 views
0

我有这样的(部分)布局:如何“锁定”的宽度在的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数据过长,它将“推动” textView3小,直到文本内容甚至被剪切,或者如果maxLines未设置,则流向下一行。

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

ellipsize添加到tvLocation不起作用。

回答

0

通过设置android:layout_width =“0dp”将textView3和tvLocation的宽度设置为零。

+0

谢谢,这似乎这样的伎俩意见水平对齐。显然,'layout_width'比'layout_weight'有更高的偏好?你是否可以参考有关这方面的文档? –

+0

在LinearLayout的源代码中读取measureHorizo​​ntal()或measureVertical()方法。 你会明白的。 – Deng

0

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

这里,因为它是在一个表行等改变android:layout_width0dp

相关问题