Ellipsize 不适用于自定义 listView 中的 textView [英] Ellipsize not working for textView inside custom listView

查看:16
本文介绍了Ellipsize 不适用于自定义 listView 中的 textView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图,其中包含由下面的 xml 布局定义的自定义对象.我希望 id 为info"的 textView 在一行上被省略,我已经尝试使用属性

I have a listView with custom objects defined by the xml-layout below. I want the textView with id "info" to be ellipsized on a single line, and I've tried using the attributes

android:singleLine="true"
android:ellipsize="end"

没有成功.

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

If I set the layout_width to a fixed width like e.g.

android:layout_width="100px"

文本被截断了.但出于便携性原因,这不是一个可接受的解决方案.

the text is truncated fine. But for portability reasons this is not an acceptable solution.

你能发现问题吗?

<?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 坏了(去 对错误报告投票,特别是因为他们声称它不可重现)所以你必须使用一个小技巧.使用:

Ellipsize is broken (go vote on the bug report, especially since they claim it's not reproducible) so you have to use a minor hack. Use:

android:inputType="text"
android:maxLines="1"

在任何你想省略的地方.另外,不要使用 singleLine,它已被弃用.

on anything you want to ellipsize. Also, don't use singleLine, it's been deprecated.

更新:

仔细检查后,您遇到的问题是您的桌子超出了屏幕的右侧.将您的 TableLayout 定义更改为:

On closer inspection, the problem you're having is that your table is extending off the right side of the screen. Changing your TableLayout definition to:

<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.

should fix that problem, then do what I said above to ellipsize your TextView.

这篇关于Ellipsize 不适用于自定义 listView 中的 textView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆