[英]Scroll to the bottom of the Recycler View problem
I used this solution to move to the bottom of the recycler view when user hit send button to send text in EditText.当用户点击发送按钮以在 EditText 中发送文本时,我使用此解决方案移动到回收站视图的底部。 It works well if I input a single line of EditText, however if the EditText has multiple lines in it, the
smoothScrollToPosition(message_container.getAdapter().getItemCount() - 1)
wont work properly.如果我输入一行 EditText 效果很好,但是如果 EditText 中有多行,则
smoothScrollToPosition(message_container.getAdapter().getItemCount() - 1)
无法正常工作。 Assume that my EditText has 4 lines, so the view just scrolls to the first line, not the end of the EditText.假设我的 EditText 有 4 行,所以视图只是滚动到第一行,而不是 EditText 的末尾。 Is there any workaround for this?
有什么解决方法吗? thank kiu.
谢谢邱。
item_recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recycler, int dx, int dy) {
if (!shouldScroll) {
recycler.scrollTo(0, 0);
item_recyclerview.requestFocus();
}
}
});
我有一个错误,我将回收器视图放在滚动视图中,所以我上面使用的代码没有按预期工作,只需删除滚动视图,一切又正常了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.