简体   繁体   English

在ScrollView(ANDROID)内的无限RecycleView中保留滚动位置

[英]Retain scroll position in infinite RecycleView inside ScrollView (ANDROID)

I have RecycleView inside the ScrollView that can infinite scroll and always load new data with paging. 我在ScrollView中具有RecycleView,它可以无限滚动并始终通过分页加载新数据。 Is there any way to save my scroll position (RecycleView and ScrollView) when Activity get onPause(), and restore when onResume(). 有什么方法可以在Activity获得onPause()时保存我的滚动位置(RecycleView和ScrollView),并在onResume()时恢复。 Just like Instagram, Facebook, etc. when we click for detail posting and back to the timeline exactly in the same position when we left before enter code here . 就像Instagram,Facebook等一样,当我们单击以查看详细信息并返回到时间轴时,它们在我们离开enter code here之前离开的位置完全相同。

My advice : use RecycleView inside another RecycleView. 我的建议:在另一个RecycleView中使用RecycleView。 So for RecycleView you can use this strategy : 1) Save last visible item position 2) Do some manipulations 3) Restore your position 因此,对于RecycleView,您可以使用以下策略:1)保存最后一个可见项目的位置2)做一些操作3)恢复您的位置

int lastViewedPosition = ((LinearLayoutManager)rv.getLayoutManager()).findLastVisibleItemPosition();

//some manipulations 

rv.getLayoutManager().scrollToPosition(lastViewedPosition + data.size() - 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM