如何保持对设备旋转地图的状态? [英] How to keep map state on device rotation?
问题描述
我有一个嵌套的片段,我想,当设备方向变化以保持状态。
I have a nested fragment that i would like to maintain the state when the device orientation changed.
这是这样的:
我实例在嵌套片段的图形页面,当装置旋转时,用户必须在相同的位置在哪里。
我怎样才能做到这一点?
I'm instantiate a mapView in the nested fragment and when the device is rotated the user must be in the same place where it was. How can I accomplish this?
感谢您
推荐答案
好了,所以我犯了一个错误。
我呼吁片段父功能的 setRetainInstance(真)的,我不应该。
Ok, so i was making a mistake. I was calling the function setRetainInstance(true) on the fragment parent and i shouldn't.
删除该行后,这是非常简单的,以保持国家的地图上设备的方向。
所有我要做的就是节省的的onSaveInstanceState 的这样的一些值:
After deleting that line, it was very simple to keep the map state on device orientation. All i had to do was to save some values on onSaveInstanceState like this:
bundle.putDouble("lat", mMap.getCameraPosition().target.latitude);
bundle.putDouble("lon", mMap.getCameraPosition().target.longitude);
bundle.putFloat("zoom", mMap.getCameraPosition().zoom);
然后在的onCreate,我恢复地图状态的是这样的:
Then on onCreate, i restore the map state like this:
bundle.getDouble("lat");
bundle.getDouble("lon");
bundle.getDouble("zoom");
这篇关于如何保持对设备旋转地图的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!