android imagespan image is cut error in singleline textview

后端 未结 2 958
野性不改
野性不改 2021-01-07 10:52

I use ImageSpan to display image in textview. The TextView is sinlgline with end ellipsize. When image is in the end of textview and there is not enought space for it. I thi

相关标签:
2条回答
  • 2021-01-07 11:32

    I use TextUtils.ellipsize for the text before setting it into TextView.

    CharSequence cs = TextUtils.ellipsize(s, textView.getPaint(), textView.getWidth() - textView.getPaddingRight() - textView.getPaddingLeft(), TextUtils.TruncateAt.END);
    textView.setText(cs);
    
    0 讨论(0)
  • 2021-01-07 11:35

    if textview set wrap_content or match_parent,you had better call TextUtils.ellipsize in textview.post();

    tv.post(new Runnable() {
            @Override
            public void run() {
                tv.setText(TextUtils.ellipsize(tv.getText(), (TextPaint) tv.getPaint(), tv.getWidth() - tv.getPaddingRight() - tv.getPaddingLeft(), TextUtils.TruncateAt.END));
            }
        });
    
    0 讨论(0)
提交回复
热议问题