Ellipsize不工作的TextView中自定义的ListView内 [英] Ellipsize not working for textView inside custom listView
问题描述
我有与下面的XML布局定义的自定义对象的ListView。我想ID为信息上一行被ellipsized 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"
您要ellipsize什么。另外,不要使用单线
,它已经去precated。
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">
要解决这个问题,然后做什么,我说上面ellipsize你的的TextView
。
这篇关于Ellipsize不工作的TextView中自定义的ListView内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!