用过百度地图的人多很忧伤,各种bug, 已无力吐槽,最无语的可能就是会出现黑屏现象,比如一个Activity包含三个Fragment, 其中一个Fragment嵌套MapView使用,在切换这三个Fragment时会出现明显的黑屏,这个问题出现很久了,很早的SDK版本就存在,现在最新的SDK版本依然存在这个问题,解决方案如下:
1,在使用MapView的Fragment的onResume/onPause方法中手动调用设置view是否可见,具体如下:
@Override
protected void OnPause(){
mMapView.setVisibility(View.INVISIBLE);
mMapView.onPause();
super.onPause();
}
进入页面时
@Override
protected void onResume(){
mMapView.setVisibility(View.VISIBLE);
mMapView.onResume();
super.onResume();
}
2, Activity对应XML布局中单独使用一个View来替换嵌套有MapView的Fragment,需要显示该Fragment 时,设置该View为可见,不使用时设置为不可见。
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/mapFrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/otherFrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" >
3,整个Activity生命周期中使用同一个嵌套有MapView的Fragment 对象,不用重复new实例, 这是最关键的。
Demo工程下载地址:http://download.csdn.net/detail/easyer2012/8968903