I have a rectangular tile and I want to fit the image and some text into it. The image should not overlap the text, and the size of the image and text may vary.
The process must be manually encoded, as we must fine-tune it according to the needs of our customers.
I tried to first measure the displayed text borders with getTextBounds() or measureText() , and then adapting the font size and image size so that they do not overlap.
This works fine if the text is on only one line.
But if a TextView wraps text on multiple lines, I cannot predict the boundaries of the text, since I do not know where TextView will insert automatic line breaks.
How to find out the position in the text where TextView inserts an automatic line break?
Example: Given text
Lorem ipsum dolor sit amet
which will be displayed as
| Lorem ipsum | | dolor sit amet |
I need a function that converts
Lorem ipsum dolor sit amet
to
Lorem ipsum \ndolor sit amet
source share