How do I place new items at the top of a recyclerView?

后端 未结 2 942

I\'m adding content to my database (Firebase) which are suppose to be loaded into my recyclerview. But the new content always appear at the bottom of the re

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-07 14:29

    If you want to appear new Items on the top just Add this code in your Activity. you need to reverse your RecyclerView, then you totally need this code segment. It does not require any modification or any special library. It’s so simple to work on LinearLayoutManager .

     LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
            mLayoutManager.setReverseLayout(true);
            mLayoutManager.setStackFromEnd(true);
            recyclerView.setLayoutManager(mLayoutManager);
    

    First you need to create a LinearLayoutManager object and use “setReverseLayout(true)” and “setStackFromEnd(true)” methods to reverse and add item at the end.

提交回复
热议问题