如何使用maxLength以3个点结束TextView [英] How to end TextView with 3 dots by using maxLength
问题描述
我的布局中有一个 TextView
,它是 layout_width
中的 wrap_content
.最多限制为15个字符,因此我使用的是 maxLength
.
I have a TextView
in my layout which is wrap_content
in layout_width
. It is limited to maximum of 15 characters so I'm using maxLength
.
我需要以3个点(...)结尾这个 TextView
,并且只有在我给 layout_width
固定大小的dp时,这种情况才会发生,这是我不做的不想做.
I need to end this TextView
with 3 dots (...) and it happens only when I give the layout_width
a fixed size in dp, something that I don't want to do.
我知道可以通过编程在第15个字符后修剪字符串,然后添加3个点,但这是有可能的,但是我更喜欢使用XML来实现.
I know it is possible programmatically by trimming the string after the 15th character and then adding the 3 dots, but I prefer to do that by XML.
有什么主意如何以3个点结束文本并保留wrap_content吗?
Any idea how to end the text with 3 dots and leave it wrap_content?
<TextView
android:id="@+id/inbox_contactName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:maxLines="1"
android:ellipsize="end"
android:singleLine="true"
android:maxLength="15"
android:textColor="#0670b4"
android:textSize="16sp" />
推荐答案
这将解决您的问题,在XML代码中使用 ellipsize
属性
This will solve your problem, Use ellipsize
Property in your XML Code
android:ellipsize="end" <!-- This makes the magic ... thing -->
android:maxEms="15" <!-- Limit of the Text -->
android:singleLine="true" <!-- In case if you want everything in one line -->
: singleLine
已被弃用.改用 maxlines ="1"
.
这篇关于如何使用maxLength以3个点结束TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!