android - 如何添加按钮并将其覆盖在我的 Google 地图片段上
问题描述
所以我有自己GoogleMap
使用我的 API 密钥。我可以找到我的位置,但打开应用程序时没有任何按钮。如果我尝试通过 android 设计布局单击并拖动任何按钮,则不允许这样做。
这就是我的activity_maps.xml
样子:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
当查看它旁边的 android 手机视图时,它只是说,我不确定如何在这张地图的顶部添加一个按钮,如果可能的话,甚至在它的下方添加一个按钮。我知道ConstraintLayout
and FrameLayout
,但是在添加其他代码时,我只是得到“多根错误”并且无法实现我想要的。
谁能帮帮我?
解决方案
也许一个更简单的解决方案是在您的地图前面设置一个叠加层,使用FrameLayout
或RelativeLayout
将它们视为您活动中的常规按钮。您应该以从后到前的顺序声明您的图层,例如,在按钮之前映射,尝试以下布局,看看它是否适合您
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapActivity" >
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical"
class="com.google.android.gms.maps.SupportMapFragment"/>
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:background="#80000000"
android:padding="4dp" >
</FrameLayout>
推荐阅读
- angular - 在角度 6 中禁用 mat-stepper 上先前完成的步骤
- java - Firebase admin java SDK - 在事件发生时获取更改数据而不是所有数据
- node.js - 我应该如何利用 Neo4j 数据库对 nodeJs API 进行自动化测试
- sql - 嵌入Java时SQL查询不起作用
- javascript - 将本地时区时间戳转换为 UTC 时间戳
- powershell - Powershell 输出日志文件
- sql - SQL 查询从一个表中的 XML 获取值并使用该值更新另一个表中的列
- jquery - 重定向到具有多个参数的另一个视图,位于不同的控制器 jquery
- android - 尝试显示 50 标记时,Google 地图滚动缓慢且手机应用显示 ANR
- neo4j - 如何在 Neo4j Desktop 中重命名新项目?