我在MainActivity中使用Firebase RecyclerView.Apdapter
和Firebase UI。当我打开另一个活动并返回主活动时,滚动位置移动到顶部。使用Firebase RecyclerView关闭其他活动后如何获得相同的滚动位置?
要解决这个问题,你需要知道负责持有layout state
(并恢复它)的组件是你的LayoutManager
中使用的RecyclerView
。为此,您可以覆盖onSaveInstanceState()
方法并将位置直接存储在Bundle
对象中。
要取回它,只需覆盖onRestoreInstanceState()
方法并从Bundle
对象获取位置。
最后,只需在onStart()
方法中使用以下代码行:
layoutManager.onRestoreInstanceState(yourListState);