Skip to content

Instantly share code, notes, and snippets.

@florinmuscalu
Created December 13, 2020 21:49
Embed
What would you like to do?
String s = "";
int counter = 1;
public void addLine(View view) {
TextView tv = findViewById(R.id.test_text);
s = s + "Line " + counter + "<br>";
counter++;
tv.setText(Html.fromHtml(s, Html.FROM_HTML_MODE_LEGACY));
int scrollAmount = tv.getLayout().getLineTop(tv.getLineCount()) - tv.getHeight();
if (scrollAmount > 0)
tv.scrollTo(0, scrollAmount);
else
tv.scrollTo(0, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment