Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Recycleview- Show first item at bottom and scroll it from bottom to top for next items

I have a recyclerview with several items. I need to show the items starting from bottom i.e. first item should be displayed at bottom and after scrolling from bottom to top, further items will get displayed. For this what I tried is,

linearlayoutManager.setStackFromEnd(true);

This helped to start the items from bottom. But when there are several items, more than the size to fit into the screen at the same time then the first item goes moving at the top as the item count increases.

I also tried with

linearlayoutManager.scrollToPosition(0);

This didn't change anything.

Here is an image showing what I am looking for.

enter image description here

There are few more items in the list above which are still not visible.

Here how it looks When these items are scrolled, enter image description here.

I have checked view hierarchy of this view in the image which only shows a recyclerview and the items within it. And the recyclerview's height is match_parent i.e. the top space with no items showing another view underneath of the recyclerview which is a google map. I just need to know how I can achieve this feature of the recyclerview without using more extra views.

Any help would be greatly appreciated..!!

like image 628
App developer Avatar asked Apr 20 '17 08:04

App developer


3 Answers

Try to init your Linear layout as follow

RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, true);

The third boolean indicates that it should reverse the items or not. But remember that your datas should be sorted from newest to oldest also.

like image 123
Lê Thái Phúc Quang Avatar answered Sep 29 '22 08:09

Lê Thái Phúc Quang


Try using a reversed LinearLayoutManager:

LinearLayoutManager linearlayoutManager = new LinearLayoutManager(context, VERTICAL, true);
like image 24
Bartek Lipinski Avatar answered Sep 29 '22 08:09

Bartek Lipinski


LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true);
linearLayoutManager.setStackFromEnd(true);
linearLayoutManager.setReverseLayout(true);

Then once your data is populated

adapter.notifyDataSetChanged();
recyclerView.post(new Runnable() {
@Override
public void run() {
   recyclerView.smoothScrollToPosition(0);
    }
});
like image 31
Robert Goodrick Avatar answered Sep 29 '22 08:09

Robert Goodrick