Android 重叠的地图视图不';我的行为似乎不正确

Android 重叠的地图视图不';我的行为似乎不正确,android,google-maps-android-api-2,Android,Google Maps Android Api 2,我在一个活动中有一个地图视图,在一个视图中有另一个地图视图,当单击某个按钮时,该视图将在活动前面弹出)。问题是,当视图弹出时,该区域不是显示指定区域中的新地图,而是空的(并且是透明的),因此,活动的地图是可见的,而不是视图的(无论我是否添加了一些bg颜色) 无论如何,为了解决这个问题,我创建了一个简单的活动,它有两个重叠的地图视图,点击按钮可以在前面切换其中一个 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/

我在一个活动中有一个地图视图,在一个视图中有另一个地图视图,当单击某个按钮时,该视图将在活动前面弹出)。问题是,当视图弹出时,该区域不是显示指定区域中的新地图,而是空的(并且是透明的),因此,活动的地图是可见的,而不是视图的(无论我是否添加了一些bg颜色)

无论如何,为了解决这个问题,我创建了一个简单的活动,它有两个重叠的地图视图,点击按钮可以在前面切换其中一个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:map="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">

    <Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Toggle" />


    <RelativeLayout     android:layout_width="match_parent"
        android:layout_height="100dip">

             <RelativeLayout android:id="@+id/mapview1_content"
                    android:layout_width="match_parent"
                    android:layout_height="80dip"
                    android:background="#ff0000"
                    android:layout_marginTop="20dip"
                    android:layout_marginLeft="20dip">
                 <com.google.android.gms.maps.MapView
                    android:id="@+id/mapview1"
                    android:layout_margin="2dip"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>
            </RelativeLayout>

            <RelativeLayout android:id="@+id/mapview2_content"
                    android:layout_width="match_parent"
                    android:layout_height="80dip"
                    android:background="#00ff00"
                    android:layout_marginBottom="20dip"
                    android:layout_marginRight="20dip">
                 <com.google.android.gms.maps.MapView
                    android:id="@+id/mapview2"
                    android:layout_margin="2dip"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>
            </RelativeLayout>

    </RelativeLayout>

</LinearLayout>
结果不是预期的结果,当MapView2处于焦点时,它仍然在前面显示来自MapView1的图像(尽管它不可单击)

更新:


我在很多设备上都尝试过这个方法,但似乎是冰淇淋三明治或更低版本的问题…

您是否尝试过无效、重新加载或类似的方法来重新创建视图?是的,我尝试过无效、后验证,但没有成功。即使将Visibility设置为gone,您也会使用
重新创建
方法吗??
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

            try { MapsInitializer.initialize(this); } catch (GooglePlayServicesNotAvailableException e) { }

            mapView1content = (RelativeLayout)findViewById(R.id.mapview1_content);
            mapView2content = (RelativeLayout)findViewById(R.id.mapview2_content);

            mapView1 = (MapView)findViewById(R.id.mapview1);
            mapView1.onCreate(null);
            mapView1.onResume();

            mapView2 = (MapView)findViewById(R.id.mapview2);
            mapView2.onCreate(null);

            Button b2 = (Button)findViewById(R.id.button);
            b2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (ii%2==0){
                mapView1.onPause();
                mapView2.onResume();
                mapView2content.bringToFront();
                mapView1content.setVisibility(View.GONE);
                mapView2content.setVisibility(View.VISIBLE);
            }else{
                mapView2.onPause();
                mapView1.onResume();
                mapView1content.bringToFront();
                mapView2content.setVisibility(View.GONE);
                mapView1content.setVisibility(View.VISIBLE);
            }

            ii++;
        }
    });


    }