android - Android - ellipsize="end" 不显示三个点
问题描述
我正在研究一个TextView
包含在一个ConstraintLayout
.
如果它的长度超过 maxLength,我希望 ellipsize 在文本的末尾(在 TextView 中)添加三个点。
在对我的问题进行彻底研究之后,maxLines="1" 和 ellipsize="end" 似乎是最好的答案。不幸的是,它不适用于我的情况。三个点根本没有出现。
这是快照:
原始字符串是“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 中有一些覆盖椭圆大小的东西,还是我错过了 XML 文件中的一些重要内容?
解决方案
问题是:
android:maxLength="24"
删除它,因为您希望将TextView
其椭圆化。
当 TextView 的宽度不足以显示整个文本时,它会变成椭圆形。
我认为您不了解此属性android:ellipsize="end"
的全部含义。
如果它足够宽,那么最后你将看不到任何点,因为它们是不需要的。
如果您设置android:layout_width="40dp"
,那么您将看到这些点。 足够宽并且不是椭圆形的
。android:layout_width="wrap_content"
TextView
推荐阅读
- c# - 如何在 C# .NET Core 3.1 中使用 Web 套接字?
- c# - 如何在 C# selenium 测试中处理 MFA
- sql - 只有一个用户时,登录名和密码的最佳做法是什么?
- ruby-on-rails - 查询 has_one 关联为 nil 的位置
- codenameone - 对话框未在android中显示
- objective-c - FunctionImport 抛出 500 内部错误
- php - PHP Swagger - 区域级别的路径
- ruby-on-rails - Ruby 从另一个散列创建新散列,其中包含来自第一个散列的特定值
- c# - 如何将自定义对象从类序列化为光子 onserializeview 的字节数组并返回类
- ios - 我在 Swift 中收到 Beams 身份验证令牌错误