Prevent NestedScrollView scrolls to top automatically

烂漫一生 提交于 2019-12-24 07:30:58

问题


I have ListView inside NestedScrollView (do not want use RecycleListView) in my fragment. List adapter inits in onCreate and not recreated when app back to the fragment from other fragment. But my NestedScrollView then scrolls to the top (can I prevent this?). Without NestedScrollView my ListView stay at the same position.


回答1:


You should retain the list status in onPause() method on the Fragment (save it to the Bundle) and then read and set it in onResume(). Just create some constant key, save then read :-)

The value you will want to save is getScrollY() most probably. Then you will want to restore it with scrollTo(int x, int y) where x=0 and y=savedValue.

Also, you do want to use RecyclerView :-) It is really cool and works really well with NestedScrollView and CoordinatorLayout. Also, it is much easier and quicker to implement than ListView once you get the hang of it. It is also very lightweight. And I had once seen it save a puppy from a fire. RecyclerView is da man! :-D




回答2:


Remove @string/appbar_scrolling_view_behavior form the NestedScrollView layout.



来源:https://stackoverflow.com/questions/38438429/prevent-nestedscrollview-scrolls-to-top-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!