How to automatically scroll through the Recycler view in Android?

I have developed a chat application in which I can send and receive messages. But the problem is that whenever I send or receive messages, viewing the recyclers does not scroll up, so that the messages become scattered over the keyboard.

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

+8
source share
4 answers

When updating recyclerview, try running this code:

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

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

 recyclerView.smoothScrollToPosition(adapter.getItemCount()); 

I am implementing to add a new item to the list.

+6
source

Try the following method to automatically scroll to your specific position.

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

Note : position is the position of the list you want to display.

+2
source

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

Edit: Try RecyclerView.scrollTo(0, 0) immediately after sending or receiving the last message.

0
source

Source: https://habr.com/ru/post/1260327/


All Articles