我有 3 个按钮和一个 Recyclerview
。单击每个按钮,我将更新 Recyclerview
列表。我正在使用以下方式更新 Recyclerview 列表:
fun updateList(list: List<SortFilterItem>){
itemList.clear()
itemList.addAll(list)
notifyDataSetChanged()
}
问题是,如果我将列表滚动到某个位置,然后单击任何 Button
,列表会更新,但位置不会重置为起始位置。更新列表时如何重置 Recyclerview
的位置。
最佳答案
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
layoutManager.scrollToPositionWithOffset(0, 0); //Way I
layoutManager.smoothScrollToPosition(mRecyclerView, null, 0); //Way II
关于android - 如何将 recyclerview 项目列表重置为起始位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56845606/