【发布时间】:2012-12-16 08:49:21
【问题描述】:
我正在使用新的 GoogleMaps API (v2),但片段存在一些问题。我的应用程序中有两个片段(地图、列表),用户可以在它们之间切换。到目前为止,这段代码可以正常工作:
if (itemPosition == 0) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragmentpos, myMapFragment).commit();
} else if (itemPosition == 1) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragmentpos, myListFragment).commit();
}......
当我使用地图时,切换到列表片段然后返回地图片段,地图的最后位置没有保存。这不是我想要的,我希望地图在我“离开”它时处于保存状态.. 我怎样才能做到这一点?我试图将相机位置保存在
public void onSaveInstanceState(Bundle outState){
outState.putDouble("LAT", mMap.getCameraPosition().target.latitude);
outState.putDouble("LON", mMap.getCameraPosition().target.longitude);
outState.putFloat("BEAR", mMap.getCameraPosition().bearing);
...
}
并在 onCreateView() 中恢复它,但 Bundle 始终为空。如果我替换片段,则不会调用 onSaveInstanceState。
那么如何保存地图的状态呢?
【问题讨论】:
-
你能看看我的问题,让我知道我哪里出错了。这是我的问题 - stackoverflow.com/questions/14124354/…
标签: android android-fragments android-maps android-fragmentactivity