前言
使用TextView后,开启了TextView的滚动支持,添加文本时想滚动到最下面
使用
//开启滚动支持
mTxtShowTest.setMovementMethod(ScrollingMovementMethod.getInstance());
mTxtShowTest.post(() -> {
// 滚动到底部
Layout layout = mTxtShowTest.getLayout();
int padding = mTxtShowTest.getTotalPaddingTop() +
mTxtShowTest.getTotalPaddingBottom();
int line = mTxtShowTest.getLineCount() - 1;
mTxtShowTest.scrollTo(0, layout.getLineTop(line + 1) -
(mTxtShowTest.getHeight() - padding));
});