过渡到谷歌地图片段导致“错误膨胀类片段”

我加载WebView到片段作为子片段。使用按钮,然后我使用TransitionManager转换到Google Map。地图加载。然后我点击另一个按钮转换回WebView。 WebView显示。但是,当我点击按钮转换回地图,我得到一个“错误膨胀类片段”。过渡到谷歌地图片段导致“错误膨胀类片段”

出于某种原因,TransitionManager无法再次膨胀场景。我重复使用了包含Google Map的相同场景。我甚至尝试用以下方法重新初始化场景:

Scene.getSceneForLayout(sceneRoot, R.layout.activity_maps, context); 

但它没有帮助。当Google地图从片段中显示出来后,Google地图是否有重新初始化的问题?

UPDATE: 我想我可能已经找到了解决方案(需要尝试一下与过渡): android maps v2 crashes when reopened in fragment

回答:

对我来说,我只需要使用这个代码片段,我用的时候导航抽屉。我希望它能起作用!

<?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));

}

}

以上是 过渡到谷歌地图片段导致“错误膨胀类片段” 的全部内容, 来源链接: utcz.com/qa/257526.html

回到顶部