我希望在设备旋转时提高 SupportMapFragment 的性能。似乎必须重新创建片段。我不确定这一点,但是当设备旋转时,必须重新加载地图图块。从性能的角度来看,保留和重用整个 mapfragment 而不必重新实例化该片段是有意义的。对此的任何见解将不胜感激。
我在 xml 中声明 SupportMapFragment 并使用 API 文档中描述的 SetupMapIfNeeded()。
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}