本文翻译自:Android, How to limit width of TextView (and add three dots at the end of text)?
I have a TextView
that I want to limit characters of it. 我有一个TextView
,我想限制它的字符。 Actually, I can do this but the thing that I'm looking for is how to add three dots (...) at the end of string. 实际上,我可以执行此操作,但是我要寻找的是如何在字符串末尾添加三个点(...)。 This one shows the text has continue. 这一个显示文本已继续。 This is my XML but there is no dots although it limit my text. 这是我的XML,但没有点,尽管它限制了我的文本。
<TextView
android:id = "@+id/tvFixture"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_toLeftOf = "@id/ivFixture_Guest"
android:text = "@string/test_06"
android:lines = "1"
android:ems = "3"
android:gravity = "right"
style = "@style/simpletopic.black"
android:ellipsize="end"/>
#1楼
参考:https://stackoom.com/question/J6fG/Android-如何限制TextView的宽度-并在文本末尾添加三个点
#2楼
Deprecated: 不推荐使用:
Add one more property android:singleLine="true"
in your Textview 在您的Textview中再添加一个属性android:singleLine="true"
Updated: 更新:
android:ellipsize="end"
android:maxLines="1"
#3楼
Try this property of TextView in your layout file.. 在布局文件中尝试使用TextView的此属性。
android:ellipsize="end"
android:maxLines="1"
#4楼
I think you give fix height and width of text view. 我认为您可以固定文本视图的高度和宽度。 Then your solution will work. 然后您的解决方案将起作用。
#5楼
您可以在xml中编写此行,并在其中获取textview
:
android:singleLine="true"
#6楼
I take it you want to limit width to one line and not limit it by character? 我认为您想将宽度限制为一行而不是按字符限制它? Since singleLine
is deprecated, you could try using the following together: 由于不推荐使用singleLine
,因此您可以尝试一起使用以下内容:
android:maxLines="1"
android:scrollHorizontally="true"
android:ellipsize="end"