8

I set span for spannableText and set it to TextView. After i want get width and height of this text. But the result does not take into account the change in the size of the text due to the set span. Next solution is work incorrect.

return textView.getPaint().measureText(text, 0, text.length());

1 Answers1

0

You should create a StaticLayout (or StaticLayout.Builder for API > 23) with your text and get the width and height of the text. If you are not interested the system to line break the text for you, you should give Integer.MAX_VALUE for the width parameter.

Once you create the StaticLayout, you can use getWidth(), getHeight(), getLineWidth() etc. functions for the information you are looking for.

Siyamed
  • 495
  • 2
  • 11