RecyclerView scroll to position when a new item is added

后端 未结 7 1690
南笙
南笙 2020-12-31 03:18

I want my RecyclerView to scroll to the bottom when a new item is added to the list. Below is my code:

RecyclerView.LayoutManager layoutManager = new LinearL         


        
7条回答
  •  无人及你
    2020-12-31 04:03

    This is happening because your

    recyclerView.scrollToPosition(data.size() - 1);

    is getting called first and then the list is being initialized. You need to add this line after your recycler View view is initialized. You can add this line in a handler.

提交回复
热议问题