我尝试使用ViewSwitcher在两个MapView对象之间切换(基于地理信息系统)。但我在magnifyMap (**line xyz**) mapview中得到了以下异常:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.即使在从父布局(homeScreenLayout)中删除子视图(MapViews)之后。以下是相关的代码片段。
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();发布于 2011-12-22 23:19:22
我们不能在一个基于ArcGIS的安卓应用程序中拥有一个以上的MapView对象。因此,我们不能使用ViewSwitcher来完成此任务。
https://stackoverflow.com/questions/8482532
复制相似问题