Adding items to Endless Scroll RecyclerView with a ReverseLayout recyclerview

前端 未结 2 963
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 08:15

In a normal recyclerview, the newest items are all at the top and if you add an item into the recyclerview, it pushes the existing items down and the new item takes the top posi

2条回答
  •  佛祖请我去吃肉
    2021-02-04 08:59

    Simon: solution I previously proposed here works fine with reverse layout without any modification. The only thing I'd add for reverse layout is to scroll automatically to first item when you show it first time but that's up to you. Now getting back to issue you have. You mentioned that when you scroll nothing happens. so my guess is that you initialize your recylcer view in a wrong order. Make sure you do it like this

    mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setReverseLayout(true);
    mLayoutManager.setStackFromEnd(true);
    
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new MyAdapter<>(myDataset, mRecyclerView);
    mRecyclerView.setAdapter(mAdapter);
    

    Note that layout manager gets instantiated first, then you set it and after that you provide adapter. Let me know if that was the case.

    Edit Just bringing up this from comment below:

    forget about what we have with onLoadMoreListener and all scrolling stuff just use standard RecyclerView wrapped in SwipeToRefreshLayout

提交回复
热议问题