1
在新的谷歌地圖API出來之前,我能夠實現一個谷歌地圖片段,我會添加按鈕來浮動在地圖上,將它們添加到XML文件。我可以在Raw map視圖演示活動的xml文件中使用相同的技術。演示活動是一個片段活動,但如果覺得它無法真正使用片段。它只是用來自xml文件的地圖填充其視圖。使用原始MapView浮動按鈕
是否有可能強制地圖片段加載特定的佈局,而無需創建擴展mapfragment的片段並且必須親自處理mapview生命週期。我知道這樣做通常不被推薦。
舊XML的按鈕
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0xR1g8qRRLoUp8-8gd7050zKWtMQCMDDHhizisw"
android:clickable="true" >
android:apiKey = "APIKEY" >
</com.google.android.maps.MapView>
<ZoomControls
android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:padding="10dp" />
<ImageButton
android:id="@+id/button"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@null"
android:contentDescription="@string/description"
android:padding="20dp"
android:src="@drawable/button" >
XML從rawMapViewDemo
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:id="@+id/cacbutton"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@null"
android:contentDescription="@string/description"
android:padding="20dp"
android:src="@drawable/taxi" >
</ImageButton>