How to auto scroll up Recycler view in Android?

痴心易碎 提交于 2019-12-30 00:59:08

问题


I have developed some chat application where i can send and received messages. But the problem is whenever i send or receive messages the recycler view is not scrolling to top so that messages gets diplayed above the keypad.

I have used the above mentioned recycler view android.support.v7.widget.RecyclerView.


回答1:


On updating recyclerview try to run this code :

recyclerView.post(new Runnable() {
    @Override
    public void run() {
        // Call smooth scroll  
        recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1);                                 
    }
});



回答2:


I use the following code so that the scroll is automatic until the last position:

recyclerView.smoothScrollToPosition(adapter.getItemCount());

I implement to add a new item to the list.




回答3:


Try the bellow method for auto scroll to your particular position.

adapter = new DeliveriesDateRecycleAdapter(getActivity(),sampleDatedate, position);
                recyclerviewDates.setAdapter(adapter);
                adapter.notifyDataSetChanged();
                recyclerviewDates.smoothScrollToPosition(position);

Note : position - the position of the list that you want to show.




回答4:


Have you tried RecyclerView.srollTo(int x, int y)?

Edit: Try RecyclerView.scrollTo(0, 0) directly after you have send or received the last message.



来源:https://stackoverflow.com/questions/33229806/how-to-auto-scroll-up-recycler-view-in-android

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