试了一下,可以一直保持在底部,不会上下跳动,我这里没有去计算 TextView 改变后的高度,有需要可以自己监听控件高度变化,再去 scrollToPositionWithOffset.
代码图片
https://imgur.com/a/HU30yph ```
new Thread(() -> {
while (!isFinishing() && run) {
try {
Thread.sleep(200);
} catch (InterruptedException ignored) {
}
runOnUiThread(() -> {
if (textTv != null) {
textTv.setText(textTv.getText() + "asdasdasdasdasdasdasd");
int targetPosition = adapter.getItemCount() - 1;
View targetView = linearLayoutManager.findViewByPosition(targetPosition);
int offset = recyclerView.getHeight() - targetView.getHeight();
linearLayoutManager.scrollToPositionWithOffset(targetPosition, offset);
}
});
}
}).start();
```