问题描述
我使用Recyclerview替换为列表视图我想让Recyclerview始终滚动到底部.
I Use Recyclerview Replace with list viewI 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始终滚动到底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!