Manage scroll position in scrollview during orientation change

邮差的信 提交于 2019-12-06 16:52:48

You should simply keep the index of the row that is being seen (or clicked) in your case, and persist this information thanks to onSaveInstanceState/onCreate.

After that when the rotation will occur, inside your new instance onCreate, compute the vertical offset at which you will have to scroll.

For this, you will need to add a global tree layout observer to your list cells to get their height, if it is not fixed. And then you can ask to scroll.

This method allows you to be independent of your view by keeping track of the index in the list. It will then work in portrait to landscape but also landscape to portrait.

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