【问题标题】:Android textview ellipse removes the html contentAndroid textview ellipse 去掉html内容
【发布时间】:2016-07-06 04:32:06
【问题描述】:

如果 html 内容超过 5 行,我也想在 textview 中显示它,然后修剪额外的行并在末尾添加“...”。我使用这些代码来添加修剪额外的行,

textview.setText(Html.fromHtml(message));

this.setAutoLinkMask(Linkify.ALL);
this.setMaxLines(5);
this.setEllipsize(TextUtils.TruncateAt.END);
this.setHorizontalScrollBarEnabled(true);

但它仅适用于某些文本,

        ViewTreeObserver vto = feedListRowHolder.description.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                ViewTreeObserver obs = feedListRowHolder.description.getViewTreeObserver();
                if (Build.VERSION.SDK_INT < 16) obs.removeGlobalOnLayoutListener(this);
                else obs.removeOnGlobalLayoutListener(this);

                if (feedListRowHolder.description.getLineCount() > 5) {
                    int lineEndIndex = feedListRowHolder.description.getLayout().getLineEnd(4);
                    String text = textview.subSequence(0, lineEndIndex - 3) + "...";
                    textview.setText(Html.fromHtml(text));
                }
            }
        });

问题是它从文本中删除了 html 格式。

【问题讨论】:

    标签: android html textview ellipse


    【解决方案1】:

    更改此String text = textview.subSequence(0, lineEndIndex - 3) + "...";

    String text = message.subSequence(0, lineEndIndex - 3) + "...";

    【讨论】:

      猜你喜欢
      • 2017-04-17
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 2015-08-07
      • 1970-01-01
      • 2016-11-10
      • 2015-06-13
      • 2011-11-30
      相关资源
      最近更新 更多