簡體   English   中英

在Android上向Google Maps Marker添加自定義頁腳按鈕

[英]Adding custom footer buttons to Google Maps Marker on Android

當我在MapFragment中單擊Marker時,地圖底部會出現兩個按鈕(用於路徑和搜索)。 我該如何自定義這些按鈕?

我在這里搜索了一些提示,但只找到了如何在信息窗口中添加按鈕......

謝謝。

您可以使用帶有3 FrameLayout ,並將底部按鈕的android:visibility設置為invisible

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent">

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment"
          />

    <Button
        android:layout_gravity="bottom|left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        android:text="Button 1"/>

    <Button
        android:layout_gravity="bottom|right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        android:text="Button 2"
        />

</FrameLayout>

(如果你沒有設置android:visibility="invisible" ,你可以在mapFragment的底部看到這兩個按鈕,見下圖)

在此輸入圖像描述

onMarkerClick方法中,您可以將這兩個按鈕的不可見性更改為可見的示例代碼:

button1.setVisibility(View.VISIBLE);
button2.setVisibility(View.VISIBLE);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM