android - 如何在 MapView android 上添加按钮

标签 android button android-mapview

正如您从问题中看到的那样,我需要在 mapView 上放置一些按钮,应用程序将通过用户按下该按钮,使用当前位置刷新 mapView。 我知道如何将按钮放在上面、下面,但是如何放在 map 上??? 如果有人有一些示例代码,或者一些指导帮助,我们将不胜感激......

最佳答案

您需要使用 RelativeLayout 并将按钮放置在 MapView 的顶部。请确保不要将其放在 Google Logo 上。这是一个示例 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <com.google.android.maps.MapView android:id="@+id/google_maps"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="@string/maps_key"/>
    <Button android:id="@+id/googlemaps_select_location"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="Select"/>
</RelativeLayout>

关于android - 如何在 MapView android 上添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7193358/

相关文章:

android - 我们如何将动画/简单图像添加为视频的顶层并将其导出为 Android 中的单个视频?

java - 在将我的相对布局更改为 Linearlayout 时,它在 TTS 的 textview 上抛出空指针异常

javascript - 无法从 html 按钮调用 js 函数

android - osmdroid 将边界设置为 map View 中图像覆盖的边缘

android - 位置总是返回 null - android

java - Android studio java - 在 View 寻呼机内的 map fragment 中显示 Bottom Sheet 行为

java - 无法在 fragment 中使用适配器显示 ListView

android - 重新进入应用程序后如何在recyclerview中保存有关单击项位置的信息

ios - 删除以编程方式创建的 View iOS

android - Appcompat按钮背景样式