Android API 14和15中的TextView ellipsize会切断整个词

4

我定义了一个TextView,例如如下:

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:ellipsize="end"
        android:text="This is very long text"
        android:textSize="34pt"/>

在使用API级别14/15时,这会导致整个单词"very"被切断,我实际上显示的文本是"This is",但我需要像"This is ver"这样截断该文本。

有人可以问我如何实现这种行为吗?


这是正常的。http://developer.android.com/intl/zh-cn/reference/android/widget/TextView.html#attr_android:ellipsize - Phantômaxx
使用这个插件https://github.com/grantland/android-autofittextview非常有用。 - Fabio Venturi Pastor
1
你可以使用if想要查看完整的“跑马灯”文本。https://dev59.com/vGYr5IYBdhLWcg3w6OCd - VVB
1个回答

4

使用属性 singleline 和 ellipsize:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:text="This is very long text"
    android:textSize="34pt"/>

2
有没有其他解决方案可以不使用已弃用的singleLine属性来解决这个问题? - Tobias Reich
@TobiasReich android:maxLines="1" - Dmitriy
2
问题是,maxLines设置了行数为1。但它会在完整的单词处换行。单行则通过使用省略号来实现这一点。因此,在拥有"this is a test"这句话时,它可能会显示为"this is a"(省略了test),而单行则显示为"this is a te..."。 - Tobias Reich

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接