gpt4 book ai didi

Android - ellipsize ="end"不显示三个点

转载 作者:行者123 更新时间:2023-11-29 16:33:26 29 4
gpt4 key购买 nike

我正在处理包含在 ConstraintLayout 中的 TextView

如果文本的长度超过 maxLength,我希望 ellipsize 在文本末尾(在 TextView 中)添加三个点。

maxLines="1"和 ellipsize="end"似乎是对我的问题进行彻底研究后的最佳答案。不幸的是,它对我的​​情况不起作用。三个点根本没有显示。

这是快照:

enter image description here

原来的字符串是“Test for long description”(去掉了n)。它应该显示“测试长描述...”。

这是我的 xml:

<TextView
android:id="@+id/txtDescription"
android:maxLength="24"
android:maxLines="1"
android:ellipsize="end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="120dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:text="DescriptionView"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.72" />

我觉得 XML 中有一些东西覆盖了 ellipsize,还是我错过了 XML 文件中的一些重要东西?

最佳答案

问题是:

android:maxLength="24"

删除它,因为您希望 TextView 被省略。
当 TextView 的宽度不足以显示整个文本时,它会变成椭圆形。
我想你不明白这个属性 android:ellipsize="end" 是什么意思。
如果它足够宽,那么你将不会在末尾看到任何点,因为它们不是必需的。
如果您设置 android:layout_width="40dp" 那么您将看到这些点。
使用 android:layout_width="wrap_content" 时,TextView 足够宽并且不会被椭圆化。

关于Android - ellipsize ="end"不显示三个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53349367/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com