英文:
How to remove horizontal recyclerview(child) inside the recyclerview(parent) scroll to first position when notifyitemchange?
问题
我在RecyclerView
中使用多种视图类型。其中一种视图类型是具有水平方向的线性LayoutManager
的RecyclerView
。我在父RecyclerView
中加载了所有视图类型。当我更改位置为10的水平RecyclerView
项中的某个项目并使用adapter?.notifyItemChanged(10)
更新时,水平RecyclerView
会跳到第一个位置0。这会导致糟糕的用户体验。
此外,我在父和子RecyclerView
中使用了android:descendantFocusability="blocksDescendants"
和setHasFixedSize(true)
,但并没有起作用。有没有解决这个问题的方法?我还附上了参考图像
英文:
I am using multiple view type inside the recyclerview. In which one of the view type is recyclerview of linear layoutmanager with horizontal orientation. I loaded all view type inside the parent recyclerview. When I change the some item in horizonatal recyclerview item of position 10 and update by adapter?.notifyItemChanged(10)
, the horizonatal recyclerview jump to first position 0. And it creates a bad user experience.
Also I used android:descendantFocusability="blocksDescendants"
and setHasFixedSize(true)
in parent and child Recyclerview not does not works. Is there is any way to solve my problem. And also attached image for reference
Here position 1 is horizonal recyclerview
答案1
得分: 1
你可以保存RecyclerView
的布局实例,并在通知适配器后进行恢复,这将恢复布局管理器的属性,如滚动位置。
val savedInstance = recyclerView.layoutManager?.onSaveInstanceState()
adapter?.notifyItemChanged(10)
recyclerView.layoutManager?.onRestoreInstanceState(savedInstance)
英文:
You could save the RecyclerView
's layout instance and restore post notifying adapter
, this will restore layout manager properties like scroll position
val savedInstance = recyclerView.layoutManager?.onSaveInstanceState()
adapter?.notifyItemChanged(10)
recyclerView.layoutManager?.onRestoreInstanceState(savedInstance)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论