提问者:小点点

添加新项目到回收视图的顶部


我添加一个项目到回收视图位置0编程

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

这工作得很好,项目确实出现在顶部的列表中,但用户必须向上滚动才能看到新项目。

有没有什么技巧可以让项目显示在顶部,并且回收视图自动向上滚动?


共3个答案

匿名用户

好吧,你可以使用mRecyclerView. SmashScrollToPopse(int位置)

示例:

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

更新:

如果你想让滚动到某个项目非常平滑,你可以看看这个问题的答案

如何平滑滚动到某个位置的项目顶部?

匿名用户

是的,你可以这样做

mRecyclerView.smoothScrollToPosition(0);

匿名用户

试试这个

mRecyclerView.smoothScrollToPosition(0);