找到解决方案。
这个XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
android:id="@+id/tv1"
android:textColorLink="@android:color/holo_blue_dark"
android:ellipsize="end"
android:singleLine="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
android:id="@+id/tv2"
android:textColorLink="@android:color/holo_blue_dark"
android:ellipsize="end"
android:lines="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
android:id="@+id/tv3"
android:textColorLink="@android:color/holo_blue_dark"
android:ellipsize="end"
android:maxLines="1"/>
</LinearLayout>
渲染设计预览像
OK,所有ellipsizes在这里工作。 但是在真实设备上,它看起来像
android:singleLine =“true”只有工作,尽管不推荐使用。 在3个设备上测试。
是的,它的工作在xml布局预览。 但在运行时不起作用。显示[Firstword ...____] 这可能是因为我使用自定义的TextView和自己的ttf字体? –
textView.setEllipsize(TextUtils.TruncateAt.END); – PravinCG
textView.setEllipsize(TextUtils.TruncateAt.END)不起作用。 即使使用默认的TextView。 –