Recyclerview reverse layout starting scroll position issue
Solution 1:
this is very easy you have to add only single line :-
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);
Solution 2:
Note: The accepted answer misleads you.
There are 4 possibilities regarding LinearLayoutManager
's listing passion.
1.
startStackFromEnd=true
reverseLayout=true
2.
startStackFromEnd=false
reverseLayout=false
3.
startStackFromEnd=true
reverseLayout=false
4.
startStackFromEnd=false //best for chatting
reverseLayout=true //applications
each combination acts differently i don't know what exactly is your requirements, so play around these values, and i'm sure you'll get what you want.
Solution 3:
See this answer:
RecyclerView - Reverse Order
And create a setter to your RA_MessageRoom
to update your messagesGroupedByDate
. Something like that:
Collections.reverse(messagesGroupedByDate); // Reverse your dataset like in answer above
adapter.setMessagesGroupedByDate(messagesGroupedByDate); // Update your dataset in adapter
adapter.notifyDataSetChanged(); // Notify your adapter
With this every time new messages arrive your list will be updated. You need to put this snippet in your data fetch and then you can remove your postDelayed handler.