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

清疚 2023-10-19 08:08 215阅读 0赞

问题描述:

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

解决思路:

刚开始接触地图开发时,也曾经在这个问题上纠结过。刚刚学会了在地图上添加各种图层,无论是在地图上画大头针也好,绘制路线也好,都是使用图层来处理。于是落入了一种思维的定式,那就是误以为在地图上添加任何标记,只能通过图层。其实很简单,MapView也是一种控件,我们只要使用相对布局方式,就能将按钮添加到地图之上来显示。

效果截图:

Center

核心布局文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical" >
  6. <com.amap.mapapi.map.MapView
  7. android:id="@+id/mapView"
  8. android:layout_width="fill_parent"
  9. android:layout_height="fill_parent"
  10. android:clickable="true" />
  11. <Button
  12. android:id="@+id/traffic"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:background="@drawable/nav_btn_check_its_off_normal"
  16. android:layout_alignParentTop="true"
  17. android:layout_alignParentRight="true"
  18. android:layout_marginRight="10dp"
  19. android:layout_marginTop="10dp"
  20. ></Button>
  21. <Button
  22. android:id="@+id/type"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:background="@drawable/main_map_icon_layer"
  26. android:layout_below="@id/traffic"
  27. android:layout_alignLeft="@id/traffic"
  28. android:layout_marginRight="10dp"
  29. android:layout_marginTop="5dp"
  30. ></Button>
  31. </RelativeLayout>

发表评论

表情:
评论列表 (有 0 条评论,215人围观)

还没有评论,来说两句吧...

相关阅读