当前位置: 代码迷 >> Android >> Android MapView - 如何将附加控件附加到MapView所需的位置
  详细解决方案

Android MapView - 如何将附加控件附加到MapView所需的位置

热度:43   发布时间:2023-08-04 10:30:53.0

我需要在MapView的右上角放置额外的图像按钮“我当前的位置”。 任何想法如何做到这一点?

使问题通用:
1)根据MapView文档,可以将其他视图对象附加到MapView。 这个怎么做?
2)如何将此类附加控件放置在MapView上的特定位置?

以下示例在地图视图上添加了一个按钮,只需将其复制粘贴即可,然后将其移至所需位置:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/map_main"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" >


<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="0y6Hyjz6Kxo-NOV_9KHYF7-ECYeGt99xeyVU3IQ"/>

<Button 
    android:id="@+id/select_3" 
    android:layout_centerHorizontal="true"
    android:layout_marginTop="13dp"
    android:text="Center on Pickup Location" 
    style="@style/BasicButton"
    android:layout_height = "40dp"
    android:layout_width  = "280dp"
    android:onClick="selfSelectCenterLocation">
</Button>


</RelativeLayout>
  相关解决方案