我正在尝试使用ViewSwitcher
在两个对象之间切换MapView
(基于 GIS)。但我在以下位置得到以下异常magnifyMap (**line xyz**) mapview
:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
即使在MapViews
从父布局 ( homeScreenLayout
) 中删除子视图 ( ) 之后。以下是相关的片段。
1)我的第一个MapView
是 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/homeScreenLayout">
<MapView
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</MapView>
</RelativeLayout>
2)我的第二个MapView
在我的活动中:
MapView map = (MapView) findViewById(R.id.map);
MapView magnifyMap = new MapView(ActivityMap.this);
magnifyMap = _map;
magnifyMap.setExtent(new Envelope(_tappedPoint, 3.0, 3.0));
3)我ViewSwitcher
用来添加这两个视图:
homeScreenLayout.removeView(map);
homeScreenLayout.removeView(magnifyMap);
ViewSwitcher viewSwitcher = new ViewSwitcher(ActivityMap.this);
homeScreenLayout.addView(viewSwitcher);
viewSwitcher.addView(map, 0, new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// **line xyz**
viewSwitcher.addView(magnifyMap, 1, new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // line xyz
viewSwitcher.showNext();