問題描述:
在地圖上添加一個按鈕,可以響應點選。但是按鈕時固定的,地圖拖動時,按鈕不能動。
解決思路:
剛開始接觸地圖開發時,也曾經在這個問題上糾結過。剛剛學會了在地圖上添加各種圖層,無論是在地圖上畫大頭針也好,繪制路線也好,都是使用圖層來處理。于是落入了一種思維的定式,那就是誤以為在地圖上添加任何标記,隻能通過圖層。其實很簡單,MapView也是一種控件,我們隻要使用相對布局方式,就能将按鈕添加到地圖之上來顯示。
效果截圖:

核心布局檔案:
<?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"
android:orientation="vertical" >
<com.amap.mapapi.map.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
<Button
android:id="@+id/traffic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/nav_btn_check_its_off_normal"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
></Button>
<Button
android:id="@+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/main_map_icon_layer"
android:layout_below="@id/traffic"
android:layout_alignLeft="@id/traffic"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
></Button>
</RelativeLayout>