android – TextView:让它截断而不考虑单词之间的空格

前端之家收集整理的这篇文章主要介绍了android – TextView:让它截断而不考虑单词之间的空格前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何将TextView配置为在单词的中间截断?

因此,如果我有text =“Some Text”,我希望它显示为“Some Te”,假设宽度支持.

相反,我所看到的是“一些”;即使有足够的空间容纳更多的角色,它也会截断整个单词“Text”.

解决方法

这对我有用:
  1. <TextView
  2. android:layout_width="80px"
  3. android:layout_height="wrap_content"
  4. android:text="Some text"
  5. android:background="#88ff0000"
  6. android:singleLine="true"
  7. android:ellipsize="marquee"/>

或者最后用“……”:

  1. <TextView
  2. android:layout_width="80px"
  3. android:layout_height="wrap_content"
  4. android:text="Some text"
  5. android:background="#88ff0000"
  6. android:singleLine="true"
  7. />

虽然使用android:行不起作用:

  1. <TextView
  2. android:layout_width="80px"
  3. android:layout_height="wrap_content"
  4. android:text="Some text"
  5. android:background="#88ff0000"
  6. android:lines="1"
  7. android:ellipsize="marquee"/>

这很可能是一个错误,我相信我已经看到了一些错误报告.

猜你在找的Android相关文章