Solve this by doing a few things, first getting the height my TextView and loading it onto the text size to get the total number of possible lines with the TextView .
int maxLines = (int) TextView.getHeight() / (int) TextView.getTextSize();
After you get this value, you need to set the TextView maxLines to this new value.
TextView.setMaxLines(maxLines);
Set Gravity to Bottom as soon as the maximum number of lines is exceeded and it automatically scrolls down.
if (TextView.getLineCount() >= maxLines) { TextView.setGravity(Gravity.BOTTOM); }
In order for this to work correctly, you must use append() for the TextView , if you setText() , this will not work.
TextView.append("Your Text");
The advantage of this method is that it can be used dynamically regardless of the height your TextView and text size . If you decide to make changes to your layout, this code will still work.
source share