加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – Ellipsize不工作在自定义listView内的textView

发布时间:2020-12-16 01:52:45 所属栏目:百科 来源:网络整理
导读:我有一个listView与由下面的xml布局定义的自定义对象。我想让id为“info”的textView在一行上被省略,我已经尝试使用属性 android:singleLine="true"android:ellipsize="end" 没有成功。 如果我将layout_width设置为固定宽度,例如。 android:layout_width="
我有一个listView与由下面的xml布局定义的自定义对象。我想让id为“info”的textView在一行上被省略,我已经尝试使用属性
android:singleLine="true"
android:ellipsize="end"

没有成功。

如果我将layout_width设置为固定宽度,例如。

android:layout_width="100px"

文本被截断。但是出于可移植性原因,这是不可接受的解决方案。

你能发现问题吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5px"
>
<TextView  
android:id="@+id/destination"
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:textSize="22dp"
android:paddingLeft="5px"
/>

<TextView  
android:id="@+id/date"
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:textSize="15dp"
android:paddingLeft="5px"
/>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="5px"
android:paddingTop="10px" 
>
    <TableRow>
        <TextView
            android:id="@+id/driver_label"
            android:gravity="right"
            android:paddingRight="5px"
            android:text="@string/driver_label" />
        <TextView
            android:id="@+id/driver" />
    </TableRow>
    <TableRow>
        <TextView
            android:id="@+id/passenger_label"
            android:gravity="right"
            android:paddingRight="5px"
            android:text="@string/passenger_label" />
        <TextView
            android:id="@+id/passengers" />
    </TableRow>
    <TableRow>
        <TextView
            android:id="@+id/info_label"
            android:gravity="right"
            android:paddingRight="5px" 
            android:text="@string/info_label"/>
        <TextView
            android:id="@+id/info"
            android:layout_width="fill_parent"
            android:singleLine="true"
            android:ellipsize="end" />
    </TableRow>
</TableLayout>
Ellipsize是破碎的(去 vote on the bug report,尤其是因为他们声称它不可重复),所以你必须使用一个小小的黑客。使用:
android:inputType="text"
android:maxLines="1"

在任何你想椭圆化。另外,不要使用singleLine,它已被弃用。

更新:

仔细检查一下,你所遇到的问题是你的桌子从屏幕的右侧延伸。将TableLayout定义更改为:

<TableLayout
    android:id="@+id/info_table"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="5px"
    android:paddingTop="10px"
    android:shrinkColumns="1">

应该解决这个问题,然后做我上面说的省略你的TextView。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读