为椭圆化的 TextView 提供 Spanned 变量也会导致单行的椭圆化,如何防止这种情况发生?

Providing Spanned variable to ellipsized TextView results in ellipsize for single line too, how to prevent this?

我有一个回收站视图列表,每个列表项都有一个文本视图,它是从网络响应中填充的,响应可以是普通文本,也可以是最常见的 html,下面是代码。

Spanned htmlAsSpanned = Html.fromHtml(item.getDescription().trim());
holder.content.setText(htmlAsSpanned);

请注意,我已将此文本视图的 ellipsize 设置为 true,将 maxlines 设置为 1 "content"。以下是文本视图中可能的输入文本

<p>some text </p>

当有多行文本发生省略时,这是预期的。 但是,当输入有单行时,也会应用 ellipsize!,所以上面的行会像

some text ... 

如何防止单行 html 输入被省略?

注意:只有当我转换为 spanned 并通过内容的 html text.Without 转换时,才会发生这种情况,只有当它超过一行时它才会椭圆化,这完全没问题。

以下是对我有用的解决方案...

  Spanned htmlDescription = Html.fromHtml(item.getDescription());
  String descriptionWithOutExtraSpace = new String(htmlDescription.toString()).trim();
  holder.content.setText(htmlDescription.subSequence(0, descriptionWithOutExtraSpace.length()));