如何让 RecyclerView 始终滚动到底部 [英] how to keep RecyclerView always scroll bottom

查看:187
本文介绍了如何让 RecyclerView 始终滚动到底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Recyclerview 替换为列表视图我想让 Recyclerview 始终滚动到底部.

I Use Recyclerview Replace with list view I want to keep Recyclerview always scroll bottom.

ListView 可以使用这个方法 setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL)

ListView can use this method setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL)

RecyclerView 我使用方法 smoothScrollToPosition(myAdapter.getItemCount() - 1)

RecyclerView I use method smoothScrollToPosition(myAdapter.getItemCount() - 1)

但是当软键盘弹出时,它会替换 RecyclerView 内容.

but when Soft keyboard Pop ,its replace RecyclerView content.

推荐答案

这是因为 RV 认为它的参考点是 TOP 并且当键盘出现时,RV 的大小由父级更新,RV 保持其参考点稳定.(因此将顶部位置保持在同一位置)

This is because RV thinks its reference point is TOP and when keyboard comes up, RV's size is updated by the parent and RV keeps its reference point stable. (thus keeps the top position at the same location)

您可以将 LayoutManager#ReverseLayout 设置为 true在这种情况下,RV 将从适配器的末端开始布局项目.

You can set LayoutManager#ReverseLayout to true in which case RV will layout items from the end of the adapter.

例如适配器位置 0 位于底部,1 位于其上方等...

e.g. adapter position 0 is at the bottom, 1 is above it etc...

这当然需要您颠倒适配器的顺序.

This will of course require you to reverse the order of your adapter.

我不确定,但设置 从末尾开始堆栈 也可以在不重新排序适配器的情况下为您提供相同的结果.

I'm not sure but setting stack from end may also give you the same result w/o reordering your adapter.

这篇关于如何让 RecyclerView 始终滚动到底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆