0

我试图从其他问题中解答同样问题的很多答案,但是他们都没有帮助我。无法在Android地图上叠加按钮

我只需要在Google Map片段上放一个按钮。

下面的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:background="#ffffff"> 


<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="com.henriquevoni.petgo.MapFragment"/> 

<Button 
    android:id="@+id/button7" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:layout_gravity="end|center_horizontal" 
    android:layout_marginBottom="39dp" 
    android:layout_marginLeft="8dp" 
    android:background="#359c5e" 
    android:text="Next" 
    android:textColor="#ffffff" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" /> 


</RelativeLayout> 

这里是一个screenshot of the map

+0

使用Android Studio的Layout Inspector查看按钮在哪里清盘。 – CommonsWare

+0

在父亲的RelativeLayout上,尝试将layout_width更改为match_parent – Artem

+0

您的Fragment正在消耗整个屏幕。该按钮因此被推掉。如果你想要的话,先把按钮放在“片段上”,我相信 –

回答

0

ü可以尝试这样

<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"> 


<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="wrap_content" 
      android:layout_weight="1" 
tools:context="com.henriquevoni.petgo.MapFragment"/> 

<Button 
    android:id="@+id/button7" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal|bottom" 
    android:layout_marginBottom="39dp" 
    android:layout_marginLeft="8dp" 
    android:background="#359c5e" 
    android:text="Next" 
    android:textColor="#ffffff" 

    /> 


</FrameLayout> 

或U也可以这样做

如果这是你想...只需在Fragment中添加按钮。

<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"> 


<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="wrap_content" 
      android:layout_weight="1" 
tools:context="com.henriquevoni.petgo.MapFragment"> 

<Button 
    android:id="@+id/button7" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal|bottom" 
    android:layout_marginBottom="39dp" 
    android:layout_marginLeft="8dp" 
    android:background="#359c5e" 
    android:text="Next" 
    android:textColor="#ffffff" 

    /> 
</fragment> 

</FrameLayout>