无法使用 ViewSwitcher 切换地图视图
我正在尝试使用 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.
即使从父布局 (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
在我的 Activity 中:
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
添加这 2 个意见:
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();
I am trying to use ViewSwitcher
to switch between two MapView
objects (GIS based). But I get the following exception at magnifyMap (**line xyz**) mapview
:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
even after removing the child views (MapViews
) from the parent layout (homeScreenLayout
). Following are the relevant snippets.
1) My 1st MapView
is in 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) My 2nd MapView
is in my Activity:
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) I am using ViewSwitcher
to add these 2 views:
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在一个基于 ArcGIS 的 Android 应用程序中,我们不能有多个 MapView 对象。因此,我们不能使用ViewSwitcher来完成这个任务。
We cannot have more than one MapView objects in a single ArcGIS based Android application. Hence, we cannot use ViewSwitcher to accomplish this task.