Force next word to a new line if the word is too long for the textview
First you can get the text paint using TextView.getPaint()
, then each time you add a new word(Hi, I, am, etc), call measureText
on the paint. If the result length is longer than the available width of your TextView, add a \n
before the new word.Reset the data and repeat the steps.
android:breakStrategy="simple"
Add this in your Textview. It worked for me!