【问题标题】:Textview three dots when text truncates but also include the ending quote [duplicate]文本截断时的Textview三个点,但还包括结尾引号[重复]
【发布时间】:2018-11-02 06:50:37
【问题描述】:

我有一个带有属性的文本视图

android:maxLines="1"

如果文本太长,它会截断并添加三个点。即

如果我想输入文字(包括引号) “你好世界一二三四”

会显示

“你好世界一二....

但我想显示结束语。

“你好,世界一二……”

如何做到这一点??

【问题讨论】:

  • 我猜你必须用两个 textViews 来做。一个带有截断的一个,并在末尾带有引号的文本视图。
  • 检测 textview 是否为椭圆形可能会有所帮助:stackoverflow.com/questions/4005933/…

标签: android performance android-layout textview spannable


【解决方案1】:
<TextView
    android:id="@+id/activity_main_tv_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/text"
    />

在你的活动中,

val stringText = "hello world one two three four"
findViewById<TextView>(R.id.activity_main_tv_text).text = String.format("\"%s\"", stringText)

【讨论】:

  • 字符串不是常量
  • 这是您可以动态执行的方法。
  • 这是一个非常简单的解决方案,可以满足您的需求。
  • 我试过了,但是没用。
  • 所以这里的问题是文本应该足够长以显示那里的点“你好世界一二三...”,你只是分配一个具有特定格式的字符串。
猜你喜欢
  • 1970-01-01
  • 2016-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多