(android 地图开发) 高德地图添加浮动按钮
java哥
阅读:717
2021-04-01 10:20:38
评论:0
问题描述:
在地图上添加一个按钮,可以响应点击。但是按钮时固定的,地图拖动时,按钮不能动。
解决思路:
刚开始接触地图开发时,也曾经在这个问题上纠结过。刚刚学会了在地图上添加各种图层,无论是在地图上画大头针也好,绘制路线也好,都是使用图层来处理。于是落入了一种思维的定式,那就是误以为在地图上添加任何标记,只能通过图层。其实很简单,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>
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。