![](/img/trans.png)
[英]Preventing recyclerview from reloading after returning back from another activity
[英]Scroll position of RecyclerView lost when returning back to activity from another activity
我在 MainActivity 中将 Firebase RecyclerView.Apdapter
与 Firebase UI 一起使用。 当我打开另一个活动并返回主活动时,滚动位置移动到顶部。 使用 Firebase RecyclerView 关闭其他活动后如何具有相同的滚动位置?
为了解决这个问题,您需要知道负责保持layout state
(并恢复它)的组件是RecyclerView
使用的LayoutManager
。 为此,您可以覆盖onSaveInstanceState()
方法并将位置直接存储在Bundle
对象中。
要取回它,只需覆盖onRestoreInstanceState()
方法并从Bundle
对象取回位置。
最后只需在onStart()
方法中使用以下代码行:
layoutManager.onRestoreInstanceState(yourListState);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.