我将一个WebView作为子片段加载到片段中。然后使用按钮,我使用TransitionManager转换到Google Map。地图加载。然后我点击另一个按钮转换回WebView。 WebView显示。但是当我点击按钮转换回地图时,我得到一个"错误的类膨胀类片段"。
由于某种原因,TransitionManager无法再次膨胀场景。我重复使用包含Google Map的相同场景。我甚至尝试用以下方式重新初始化场景:
Scene.getSceneForLayout(sceneRoot, R.layout.activity_maps, context);
但它没有帮助。谷歌地图在从片段中显示后被破坏后是否有重新初始化的问题?
更新 我想我可能已经找到了解决方案(需要尝试使用转换): android maps v2 crashes when reopened in fragment
答案 0 :(得分:0)
在我的情况下,当我使用导航抽屉时,我只需要使用带有片段的代码。我希望它有效!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainl"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</RelativeLayout>
MainActivity
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction();
SupportMapFragment mFRaFragment = new MapFragmentD();
Bundle args = new Bundle();
args.putDouble("lat", 30.375321);
args.putDouble("lng", 69.345115);
mFRaFragment.setArguments(args);
mTransaction.add(R.id.mainl, mFRaFragment);
mTransaction.commit();
try {
MapsInitializer.initialize(getApplicationContext());
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
}
MapFragmentD
public class MapFragmentD extends SupportMapFragment {
GoogleMap mapView;
private static LatLng position ;
// ArrayList<Map> mapclass;
@Override
public void onCreate(Bundle arg0) {
super.onCreate(arg0);
}
@Override
public View onCreateView(LayoutInflater mInflater, ViewGroup arg1,
Bundle arg2) {
return super.onCreateView(mInflater, arg1, arg2);
}
@Override
public void onInflate(Activity arg0, AttributeSet arg1, Bundle arg2) {
super.onInflate(arg0, arg1, arg2);
}
@SuppressWarnings("unchecked")
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// mapclass = (ArrayList<Map>)getArguments().getSerializable("Map");
mapView = getMap();
mapView.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// for(int i = 0; i < mapclass.size(); i++)
// {
position = new LatLng(getArguments().getDouble("lat"), getArguments().getDouble("lng"));
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.draggable(true);
markerOptions.position(position);
markerOptions.title("test");
// markerOptions.snippet(mapclass.get(i).getSpeciality());
markerOptions.icon(BitmapDescriptorFactory.defaultMarker());
mapView.addMarker(markerOptions);
// }
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(position)
.zoom(7)
.bearing(90)
.tilt(30)
.build();
mapView.animateCamera(CameraUpdateFactory.newCameraPosition(
cameraPosition));
}
}