I have a rectangular tile, and I want to fit an image and some text into it. The image must not overlap the text, and the sizes of the image and the text can vary.
The process must be hand-coded, since we have to fine-tune it according to our client's needs.
I tried the approach of first measuring the rendered text bounds using getTextBounds()
or measureText()
and then adapting the font size and the image size so they don't overlap.
This works fine if the text is only on one line.
But if TextView
wraps the text onto multiple line, I cannot predict the text bounds, since I don't know where TextView
would insert the automatic line breaks.
How can I find out the positions in the text where TextView
inserts an automatic line break?
Example: Given the text
Lorem ipsum dolor sit amet
which would be rendered as
| Lorem ipsum |
| dolor sit amet |
I need a function that converts
Lorem ipsum dolor sit amet
to
Lorem ipsum \ndolor sit amet