Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto scroll up Recycler view in Android?

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.

like image 287
Kalaiselvan Avatar asked Oct 20 '15 06:10

Kalaiselvan


People also ask

How to auto scroll Recycler view in Android?

Edit: Try RecyclerView. scrollTo(0, 0) directly after you have send or received the last message. Show activity on this post. try with following method for auto scroll to any position....you can change argument of the "notifyItemChanged" method.

How do I scroll from my recycler view to the top?

In the above code we have added recycler view to window manger as relative parent layout and add FloatingActionButton. FloatingActionButton supports CoordinatorLayout. So we have used parent layout is CoordinatorLayout. When you click on FloatingActionButton, it will scroll to top position.

Is recycler view scrollable?

To help you build apps with lists, Android provides the RecyclerView . RecyclerView is designed to be very efficient, even with large lists, by reusing, or recycling, the views that have scrolled off the screen.

How do I scroll to the bottom of my recycler view?

Recyclerview scroll to bottom using scrollToPositon. After setting the adapter, then call the scrollToPosition function to scroll the recycler view to the bottom.


1 Answers

On updating recyclerview try to run this code :

recyclerView.post(new Runnable() {
    @Override
    public void run() {
        // Call smooth scroll  
        recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1);                                 
    }
});
like image 75
Nabeel K Avatar answered Oct 16 '22 19:10

Nabeel K