Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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 使用FragmentTabHost在选项卡中显示Google地图_Android_Google Maps_Tabs_Android Fragments - Fatal编程技术网

Android 使用FragmentTabHost在选项卡中显示Google地图

Android 使用FragmentTabHost在选项卡中显示Google地图,android,google-maps,tabs,android-fragments,Android,Google Maps,Tabs,Android Fragments,我正在尝试使用from在Android应用程序中实现导航选项卡 在这样的场景中,一切都很好,但当我将Frag2视图更改为Google maps时: 从Frag1->Frag3或Frag4->返回Frag1:工作正常 从Frag1->Frag2(现在是谷歌地图)->Frag3或Frag4或返回Frag1:工作正常,直到我再次返回Frag2,然后问题发生 除了“地图”片段的布局外,所有内容都与教程中的内容相同 <?xml version="1.0" encoding="utf-8"?>

我正在尝试使用from在Android应用程序中实现导航选项卡

在这样的场景中,一切都很好,但当我将Frag2视图更改为Google maps时:

从Frag1->Frag3或Frag4->返回Frag1:工作正常

从Frag1->Frag2(现在是谷歌地图)->Frag3或Frag4或返回Frag1:工作正常,直到我再次返回Frag2,然后问题发生

除了“地图”片段的布局外,所有内容都与教程中的内容相同

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <FrameLayout
        android:id="@+id/mapFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <fragment
            android:id="@+id/shopsMaps_map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment" />

        <ImageButton
            android:id="@+id/myMapLocationButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|left"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:background="@drawable/track_icon"
            android:contentDescription="My Location" />
    </FrameLayout>

</LinearLayout>

如果您试图以框架不支持的方式使用嵌套片段,我们将不胜感激

您必须使用
getChildFragmentManager()
通过代码而不是xml添加
SupportMapFragment
,而不是现在所做的


请继续阅读并查看我的答案。

您试图以框架不支持的方式使用嵌套片段

您必须使用
getChildFragmentManager()
通过代码而不是xml添加
SupportMapFragment
,而不是现在所做的

继续读下去,看看我的答案

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <FrameLayout
        android:id="@+id/mapFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <fragment
            android:id="@+id/shopsMaps_map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment" />

        <ImageButton
            android:id="@+id/myMapLocationButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|left"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:background="@drawable/track_icon"
            android:contentDescription="My Location" />
    </FrameLayout>

</LinearLayout>
10-25 11:09:35.690: E/AndroidRuntime(25923): FATAL EXCEPTION: main
10-25 11:09:35.690: E/AndroidRuntime(25923): android.view.InflateException: Binary XML file line #11: Error inflating class fragment
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at com.arunsawad.shoplomo.tab.ShopsMaps.onCreateView(ShopsMaps.java:42)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.os.Handler.handleCallback(Handler.java:615)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.os.Looper.loop(Looper.java:137)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.app.ActivityThread.main(ActivityThread.java:4947)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at java.lang.reflect.Method.invokeNative(Native Method)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at java.lang.reflect.Method.invoke(Method.java:511)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at dalvik.system.NativeStart.main(Native Method)
10-25 11:09:35.690: E/AndroidRuntime(25923): Caused by: java.lang.IllegalArgumentException: Binary XML file line #11: Duplicate id 0x7f06002a, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
10-25 11:09:35.690: E/AndroidRuntime(25923):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:682)
10-25 11:09:35.690: E/AndroidRuntime(25923):    ... 20 more