重叠MapViews似乎没有正确行为

时间:2014-05-28 11:15:10

标签: android google-maps-android-api-2

我在一个活动中有一个MapView,另一个MapView在一个视图中,当点击某个按钮时会在活动前面弹出)。问题是当视图弹出时,而不是在指定区域中显示新的Map,此区域为空(并且是透明的),因此,可以看到活动的地图,而不是视图(不是如果我把一些bg颜色问题)。

无论如何,试图解决这个问题,我创建了一个简单的Activity,它有两个重叠的MapViews,并且在一个按钮上单击切换前面的一个或另一个。

<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>

代码:

@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++;
        }
    });


    }

结果不是预期的结果,当MapView2处于焦点时,它仍然显示前面的MapView1的图像(虽然它不可点击)

enter image description here

更新:

我在很多设备上试过这个,这似乎是IceCream Sandwich或更低的问题......

0 个答案:

没有答案