The trick here is to place another Layout container where you want to put the ZoomControls and then insert the ZoomControls into that.
The real trick is to use the RelativeLayout
rather than LinearLayout
to position the elements, as shown in this sample layout.xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="@+id/myMapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="MY_MAP_API_KEY"
/>
<LinearLayout android:id="@+id/layout_zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
The *layout_zoom* LinearLayout element is positioned in the bottom center of the screen, placing it over the middle/bottom of the MapView
.
Then within your Activity's onCreate
, get a reference to the *layout_zoom* element and insert the ZoomControl into it, much like you've already done:
LinearLayout zoomLayout =(LinearLayout)findViewById(R.id.layout_zoom);
View zoomView = myMapView.getZoomControls();
zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
myMapView.displayZoomControls(true);
The ZoomControls should now appear on a long click, without stealing the map touch events.