如何在地图片段活动上显示按钮



我正在我的 android 项目中使用 map api 来捕获当前位置并标记我想要的位置,当它成功捕获当前位置时,然后应该可以看到一个按钮,上面写着继续下一步,当用户按下它进入下一个活动时。 在正常活动中,我可以知道我们有可见性属性,但是如何在地图片段中做什么?

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
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" >
</fragment>

提前谢谢。

将地图片段包装在RelativeLayout内,并在地图片段后添加一个按钮

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!--Button appears over the map and you can position within it's parent view and toggle the visibility from the code-->
<Button
android:id="@+id/proceed_btn"
android:text="Proceed"
<!--Remove comment if you want the button to be hidden by default-->
<!-- android:visibility="gone" -->
<!--Align to the right-->
android:layout_alignParentRight="true"
<!--Align at the bottom-->
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

使用

<RealtiveLayout>

来获得这个。

您可以在内部创建按钮,并在获取当前位置时默认设置可见性 false,然后将按钮可见性设置为 true;

<fragment 
xmlns:android="http://schemas.android.com/apk/res/android"
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.example.LocationChooser">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:text="Next" 
android:padding="10dp"
android:layout_marginTop="20dp"
android:paddingRight="10dp"/>

最新更新