Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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
Java 碎片未显示在内部表格布局中_Java_Android_Android Fragments_Android Tablayout - Fatal编程技术网

Java 碎片未显示在内部表格布局中

Java 碎片未显示在内部表格布局中,java,android,android-fragments,android-tablayout,Java,Android,Android Fragments,Android Tablayout,我正在填充TabLayout中没有ViewPager的片段。但当选择一个选项卡时,我的片段不会显示在选项卡内。如果我把它放在工具栏下方,它的文本会显示在工具栏下方和选项卡顶部,但它不会显示在选项卡内部。下面是XML <android.support.v7.widget.Toolbar android:id="@+id/my_toolbar" android:layout_width="match_parent" android:layout_height="?att

我正在填充
TabLayout
中没有
ViewPager的片段。但当选择一个选项卡时,我的片段不会显示在选项卡内。如果我把它放在工具栏下方,它的文本会显示在工具栏下方和选项卡顶部,但它不会显示在选项卡内部。下面是XML

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/toolbarColor"
    android:elevation="3dp"
    />

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabGravity="fill"
    app:tabMode="fixed"
    android:layout_below="@+id/my_toolbar" />

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

每个
片段
都有一个
文本视图
首先,由于您没有提供完整的xml,我认为
工具栏
表格布局
框架布局
都在一个
相对框架内

现在据我所知,您可以正确加载
片段
s,但它们没有显示出来,因为它们隐藏在其他布局下。因此,为了解决您的问题,您需要像这样进行布局设计

<RelativeLayout 
   android:layout_width="match_parent"
   android:layout_height="match_parent"/>

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/toolbarColor"
        android:elevation="3dp" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="fixed"
        android:layout_below="@+id/my_toolbar" />

    <RelativeLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/tabs"/>
<RelativeLayout/>


只需去掉
FrameLayout
,使用
RelativeLayout
作为片段容器,并将其放在
表格布局下,查看它现在是否工作

根布局应该是线性布局我不明白为什么它必须是线性布局,但它是这样的

请给出一个答案。请注意,这并不意味着发布你的整个应用程序。你可以查看应用程序的屏幕截图,比如它如何显示你的屏幕。它只有两个空白选项卡,当选择了选项卡时,什么也没有发生,它仍然是空白的。可以在相对布局内动态更改,是的根布局是相对布局为什么不。您也可以使用
线性布局
作为碎片支架。这实际上取决于你。但正如我所建议的,越简单越好。是的,请看我的另一个问题。你的另一个问题呢?
<RelativeLayout 
   android:layout_width="match_parent"
   android:layout_height="match_parent"/>

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/toolbarColor"
        android:elevation="3dp" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="fixed"
        android:layout_below="@+id/my_toolbar" />

    <RelativeLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/tabs"/>
<RelativeLayout/>