本文介绍了显示谷歌地图使用FragmentTabHost标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我试图使用

I'm trying to implement tabs for navigation in an Android app using this tutorial from Krishnabhadra

Tab1 -> Frag1 -> Frag2

Tab2 -> Frag3

Tab3 -> Frag4

一切工作正常,像这样的情况,但是当我改变Frag2以谷歌地图:

Everything works fine with the scenario like this, but when I change Frag2 view to Google maps:

导航从Frag1 - > Frag3或Frag4 - >回Frag1:工作得很好。

Navigate from Frag1 -> Frag3 or Frag4 -> Back to Frag1: works just fine

导航从Frag1 - > Frag2(现在是谷歌地图) - > Frag3或Frag4或回Frag1:工作得很好,直到我导航回到Frag2然后再出现问题

Navigate from Frag1 -> Frag2 (now is Google maps) -> Frag3 or Frag4 or back to Frag1: works just fine until I navigate back to Frag2 again then problem occurs

一切都是安静的一样,除了布局地图碎片教程

Everything is quiet the same as in the tutorial except the layout for the maps fragment

<?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

任何帮助将AP preciated

Any help will be appreciated

推荐答案

您正试图在不被框架支撑的方式来使用嵌套的片段。

You are trying to use nested fragments in a way that is not supported by the framework.

而不是你现在在做什么,你必须使用 getChildFragmentManager()通过$ C $ SupportMapFragment 添加c和不通过XML。

Instead of what you are doing now you have to use getChildFragmentManager() to add SupportMapFragment via code and not through xml.

阅读并看看我的回答here.

这篇关于显示谷歌地图使用FragmentTabHost标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 20:13