Skip to content

Instantly share code, notes, and snippets.

@florinmuscalu
Created December 13, 2020 21:49
Show Gist options
  • Save florinmuscalu/9b424c9b1f3f53f71087ef4ca92aecb2 to your computer and use it in GitHub Desktop.
Save florinmuscalu/9b424c9b1f3f53f71087ef4ca92aecb2 to your computer and use it in GitHub Desktop.
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