Search code examples
androidandroid-layoutandroid-recyclerview

Recyclerview start from Bottom


I am loading Pictures and Strings into a Recyclerview. I once had it that the setStackfrombottom was working. But now it is not. I dont know why. This is my Code :

MessageAdapter messageAdapter = new MessageAdapter(chatsList, Chat_Room.this);
LinearLayoutManager manager = new LinearLayoutManager(getApplicationContext());
manager.setStackFromEnd(true);
recyclerView.setLayoutManager(manager);
recyclerView.setItemViewCacheSize(30);
recyclerView.setDrawingCacheEnabled(true);
recyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(messageAdapter);

The ChatsList is a List, which contains a constructor of Strings. What else can I try?

EDIT

It was not working because I used Picasso. After I changed it to Glide it was working better and more smooth. And after I set the Adapter I did this:

recyclerView.scrollToPosition(messageAdapter.getItemCount()-1);

To scroll to the last position. And now it is working fine.


Solution

  • I was recieving the Data from Firebase. So it was already in the right order. After I set the Adapter, I scrolled to the last postition:

    recyclerView.scrollToPosition(messageAdapter.getItemCount()-1);
    

    So it scrolls now to the last position. (The -1 because the Adapter starts counting at 0 )