Adding new item to the top of the RecyclerView

前端 未结 4 1256
囚心锁ツ
囚心锁ツ 2020-12-30 01:37

I am adding an item to recyclerview position 0 programamticly

public void addQuestion(Question question){
    this.questionList.add(0, question);
    notifyI         


        
4条回答
  •  死守一世寂寞
    2020-12-30 02:24

    well you can use mRecyclerView.smoothScrollToPosition(int position)

    Example:

    public void addQuestion(Question question){
        this.questionList.add(0, question);
        notifyItemInserted(0);
        mRecyclerView.smoothScrollToPosition(0);
    }
    

    UPDATE:

    if you want to make the scrolling to certain item really smooth you can have a look at answer to this question

    RecyclerView - How to smooth scroll to top of item on a certain position?

提交回复
热议问题