我正在处理包含在ConstraintLayout中的TextView。如果文本长度超过maxLength,我希望ellipsize在文本末尾添加三个点(...)。
经过详细研究后,maxLines="1"和ellipsize="end"似乎是最佳答案。但不幸的是,这对我的情况没有用。三个点根本没有显示。
以下是截图:
原始字符串为“Test for long description”(n被删除)。应该显示为“Test for long descrip...”。
以下是我的xml:
经过详细研究后,maxLines="1"和ellipsize="end"似乎是最佳答案。但不幸的是,这对我的情况没有用。三个点根本没有显示。
以下是截图:
原始字符串为“Test for long description”(n被删除)。应该显示为“Test for long descrip...”。
以下是我的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文件中漏掉了一些重要的东西吗?