是否可以在“谷歌地图活动”中添加一个按钮以将控制权传递给另一个活动?

时间:2015-03-30 07:19:47

标签: android android-layout android-fragments android-activity

我是Android新手,我想添加Google地图以显示用户当前位置,我已经使用Google地图活动完成了。现在我需要的是,我必须启用一个选项来输入目的地,所以我想在那个地图布局中添加一个按钮。是否可能?如果可能的话我该如何添加它。我选择了这个布局。

<fragment 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" android:id="@+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:layout="@layout/abc_list_menu_item_radio" />

1 个答案:

答案 0 :(得分:3)

是的,采取一个相对布局,并将片段和按钮放在相对布局中。 试试这段代码可能会对你有帮助..

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

   <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="500dp"
     tools:context=".MapsActivity"
     tools:layout="@layout/abc_list_menu_item_radio" />

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />
</RelativeLayout>