【发布时间】:2021-04-20 00:00:54
【问题描述】:
我有数据的回收器视图,当它在底部使用此代码findLastCompletelyVisibleItemPosition() 时,它将加载新数据。我的初始化数据和我的加载数据是相同的功能,只是在 recyclerview 滚动到最底部后添加更改正文请求。我的问题是当它加载新数据时,它会滚动回顶部。如何让它在同一个地方而不是向后滚动?
我已经尝试在加载数据功能中实现这一点
val recyclerViewState =list_view_history_program.layoutManager?.onSaveInstanceState()
if (loadMore > 0) {
listAdapter.notifyItemRangeChanged(loadMoreCount, listAdapter.itemCount, programNames)
listAdapter.notifyDataSetChanged()
list_view_history_program.layoutManager?.onRestoreInstanceState(recyclerViewState)
list_view_history_program.scrollToPosition(loadMoreCount)
}
但它仍然向后滚动。请帮忙
【问题讨论】:
-
是的,我也已经尝试过 Parcelable。加载数据功能和加载更多数据不一样吗?
标签: android android-recyclerview android-adapter