【发布时间】:2015-12-11 18:26:46
【问题描述】:
我加了
android:ellipsize="end"
android:maxEms="8"
android:singleLine="true"
致我的TextView,目的是在末尾显示三个点,最大文本限制为 8,但它不起作用。它既不显示点也不显示任何文本限制。
【问题讨论】:
标签: android android-layout textview
我加了
android:ellipsize="end"
android:maxEms="8"
android:singleLine="true"
致我的TextView,目的是在末尾显示三个点,最大文本限制为 8,但它不起作用。它既不显示点也不显示任何文本限制。
【问题讨论】:
标签: android android-layout textview
你添加“三点效果”的两个属性都是正确的
android:ellipsize="end"
android:singleLine="true"
但只有当TextView 在屏幕上没有任何可用空间来显示文本时才会出现这种效果。
要设置TextView 中的文本限制,您可以使用
android:maxLength="8"
但它不会添加三个点,据我所知,您必须手动添加。
类似的东西
String text = "A bit longer text";
if (text.length() > 8) {
text = text.substring(0, 8) + "...";
}
android:maxEms 与以前不同,您可以阅读更多信息
【讨论】:
android:maxLength="8"
ellipsize 不适用于宽度 wrap_content
您可以直接尝试以下示例进行测试。
<TextView
android:layout_width="30dp"
android:text="jhakjshdkajdhkjashkjdhakjsdjas"
android:maxLines="1"
android:lines="1"
android:singleLine="true"
android:ellipsize="end"
android:layout_height="wrap_content" />
希望这能帮助您解决问题。
【讨论】:
不知为何,我不小心放了
android:inputType="textCapSentences"
在我的 TextView 上阻止我的省略号显示
【讨论】:
inputType 属性,该死的椭圆终于出现了!
最佳使用方法
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:maxLines="1"
android:minEms="1"
android:singleLine="true" />
【讨论】:
设置 android:layout_width="0dp" 而不是 android:layout_width="wrap_content" 为我工作
【讨论】: