這裏的訣竅是放置另一個佈局容器,放置ZoomControls,然後在其中插入ZoomControl。
真正的竅門是使用RelativeLayout
而非LinearLayout
的元素位置,如圖此示例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>
的layout_zoom的LinearLayout元件被定位在屏幕的底部中心,將它放在MapView
的中間/底部。
中的活動的
onCreate
然後,獲取到layout_zoom元素的引用並插入zoomControl可到它,就像你已經完成:
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);
了ZoomControls現在應該出現在長按,而不會竊取地圖觸摸事件。
你是對的。沒有注意到這一點。用更好的解決方案取代了以前的答案,避免了這個問題。 – 2008-11-11 07:28:15