RecyclerView scrolling to the bottom

一世执手 提交于 2019-12-23 02:32:29

问题


I have a recyclerView with 100+ items. When user will open the activity containing the recyclerView, recyclerView's bottom should be visible without any scrolling effect. Directly last page of the adapter should be shown like whatsapp's chatting page.

I have tried by following way, but it is showing the scrolling effect when user opens the activity.

recyclerView.smoothScrollToPosition(list.size());

回答1:


You can scroll to last position of recycler view by adding this line

recyclerView.scrollToPosition(YourArraylist.size()-1);

add this after setting adapter




回答2:


LinearLayoutManager.setReverseLayout(true); this should do the trick

Documentation

Used to reverse item traversal and layout order. This behaves similar to the layout change for RTL views. When set to true, first item is laid out at the end of the UI, second item is laid out before it etc. For horizontal layouts, it depends on the layout direction. When set to true, If RecyclerView is LTR, than it will layout from RTL, if RecyclerView} is RTL, it will layout from LTR. If you are looking for the exact same behavior of setStackFromBottom(boolean), use setStackFromEnd(boolean)



来源:https://stackoverflow.com/questions/41427468/recyclerview-scrolling-to-the-bottom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!