(android 地图开发) 高德地图添加浮动按钮

来源:互联网 发布:淘宝上1元包邮赚钱吗 编辑:程序博客网 时间:2024/04/29 21:26

问题描述:

          在地图上添加一个按钮,可以响应点击。但是按钮时固定的,地图拖动时,按钮不能动。

解决思路:

         刚开始接触地图开发时,也曾经在这个问题上纠结过。刚刚学会了在地图上添加各种图层,无论是在地图上画大头针也好,绘制路线也好,都是使用图层来处理。于是落入了一种思维的定式,那就是误以为在地图上添加任何标记,只能通过图层。其实很简单,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>


 

原创粉丝点击