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