Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在应用程序中使用google Map Api2和其他片段_Android_Android Fragments_Android Support Library_Supportmapfragment_Mapfragment - Fatal编程技术网

Android 如何在应用程序中使用google Map Api2和其他片段

Android 如何在应用程序中使用google Map Api2和其他片段,android,android-fragments,android-support-library,supportmapfragment,mapfragment,Android,Android Fragments,Android Support Library,Supportmapfragment,Mapfragment,我试图创建和应用程序与一个活动,但多个片段。我正在使用android.support.v4.*构建片段。 到目前为止,我通过扩展Fragment创建的每个项目,我想在我的应用程序中使用google Map Api2 我找到的所有教程都将“SupportMapFragment”作为元素添加到布局文件中 "<fragment class="com.google.android.gms.maps.SupportMapFragment" android:layout_width="

我试图创建和应用程序与一个活动,但多个片段。我正在使用android.support.v4.*构建片段。 到目前为止,我通过扩展Fragment创建的每个项目,我想在我的应用程序中使用google Map Api2

我找到的所有教程都将“SupportMapFragment”作为元素添加到布局文件中

"<fragment
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>"
布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
  <LinearLayout
        android:id="@+id/root_container"
        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" />
    </LinearLayout>

</LinearLayout>


查看与新地图api捆绑在一起的示例。特别是,您可能对演示如何直接使用
mapview
RawMapViewDemoActivity.java
layout/raw\u mapview\u demo.xml
感兴趣。这些示例可以在
\extras\google\google\u play\u services\samples
中找到。因此,我需要覆盖所有生命周期方法,例如onCreate、onStroy、onResume、onPause。但是我如何重写oncreate方法呢?我已经用我的代码更新了这个问题。在片段OncreateView中重写oncreate方法可以吗。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
  <LinearLayout
        android:id="@+id/root_container"
        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" />
    </LinearLayout>

</LinearLayout>