尽管使用了ellipsize属性,TextView在TableLayout中不会被截断

时间:2011-12-01 20:06:03

标签: android textview tablelayout

我在表格布局中遇到了一些问题,我曾经在应用程序中显示通信数据。问题是通信数据的值可能比可用宽度更长,因此文本被切断了看起来不太好的东西。

enter image description here

为了解决这个问题,我搜索了一下,发现了一些解决方案,建议使用TableLayout上的shrinkColumns属性和TextView上应该被截断的android:ellipsize

这是表的xml

...
    <TableLayout android:id="@+id/table" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent"
    android:shrinkColumns="1"/> 
...

使用以下行布局,表的行在运行时会膨胀。

   <TableRow xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TextView android:id="@+id/type_column_text"
           android:layout_width="fill_parent"       
           android:layout_height="wrap_content"
           android:inputType="text"
           android:maxLines="1"
           android:ellipsize="end"/>
        <TextView android:id="@+id/value_column_text" 
           android:layout_width="fill_parent"       
           android:layout_height="wrap_content"
           android:inputType="text"
           android:maxLines="1"
           android:ellipsize="end"
           android:autoLink="all" />
    </TableRow>

我不知道我做错了什么,但这让我感到疯狂。有任何建议如何解决这个或如何找到它不起作用的原因?

1 个答案:

答案 0 :(得分:2)

删除说:

的行
android:inputType="text"

然后你应该得到省略号。