1

在我的应用程序中,我在操作栏中有三个选项卡。在碎片上更改蜂窝布局

Tab A : contains 2 fragments 
Tab B : contains a WebViewFragment 
Tab C : contains a WebViewFragment 

现在,我使用包含LinearLayout的全局布局。 根据选项卡,我在LinearLayout中膨胀正确的布局。但当我切换B - > A,我得到这个错误:

Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f0a0002, tag null, or parent id 0xffffffff with another fragment for com.myapp.CategoriesFragment 

什么是最好的解决方案来处理这个?

我试图removeAllViews/READD的布局,但我得到这个异常:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 

我想我已经没有选择正确的解决方案。 谢谢您的回答

回答

3

您可以选择内部容器,以便容纳片段 参考样本布局低于

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

    <LinearLayout android:id="@+id/fragment_container"  
      xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 
</LinearLayout>