Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.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 TabLayout位于Framelayout的内容下_Android_Android Fragments_Androiddesignsupport - Fatal编程技术网

Android TabLayout位于Framelayout的内容下

Android TabLayout位于Framelayout的内容下,android,android-fragments,androiddesignsupport,Android,Android Fragments,Androiddesignsupport,我有一个框架布局,其中包括一个TabLayout和一个ViewPager。显然,ViewPager加载了一个片段。现在的问题是,TabLayout在加载时位于fragment的内容之下,因此消失了 <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="

我有一个框架布局,其中包括一个TabLayout和一个ViewPager。显然,ViewPager加载了一个片段。现在的问题是,TabLayout在加载时位于fragment的内容之下,因此消失了

        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <android.support.design.widget.TabLayout
                android:id="@+id/sliding_tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

        </FrameLayout>

我怎么修理它

编辑:

使用下面的代码,我可以让它工作,但现在标签总是粘在顶部滚动时。。。不管怎样,要解决这个问题吗

<LinearLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"/>
</LinearLayout>


更改为垂直
线性布局
。然后,
ViewPager
将显示在
表格布局下方,而不是在其上方绘制。

更改为垂直
线性布局。然后,
ViewPager
将显示在
表格布局下方,而不是在其上方绘制。

您应该使用方向为“垂直”的线性布局,而不是框架布局。当您希望包含单个子级(例如片段)时,通常使用FrameLayout

应该使用方向为“垂直”的线性布局,而不是框架布局。当您希望包含单个子级(例如片段)时,通常使用FrameLayout

FrameLayout
实际上将其所有子项堆叠在彼此的顶部。所以在你的情况下,这不是你想要的行为。您应该考虑使用垂直<代码>线性布局< /代码>或<代码> RealValayOut<<代码> >

<LinearLayout
     android:id="@+id/content_frame"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="1"
     android:orientation="vertical" >

        <android.support.design.widget.TabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

</LinearLayout>

FrameLayout
实际上将其所有子项堆叠在彼此的顶部。所以在你的情况下,这不是你想要的行为。您应该考虑使用垂直<代码>线性布局< /代码>或<代码> RealValayOut<<代码> >

<LinearLayout
     android:id="@+id/content_frame"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="1"
     android:orientation="vertical" >

        <android.support.design.widget.TabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

</LinearLayout>


您应该使用线性布局或切换2个孩子您应该使用线性布局或切换2个孩子使用
LinearLayout
会导致整个事情消失。你能提供一个代码吗?好的。修正了。。。。但是当滚动时,TabLayout现在停留在顶部。。。有没有办法解决这个问题?典型的设计模式是让选项卡保持在顶部,但是您的
滚动视图
是否在
查看页面的
片段中?哦。。。我明白了。是的,片段是一个RecyclerView。使用
LinearLayout
会导致整个内容消失。你能提供一个代码吗?好的。修正了。。。。但是当滚动时,TabLayout现在停留在顶部。。。有没有办法解决这个问题?典型的设计模式是让选项卡保持在顶部,但是您的
滚动视图
是否在
查看页面的
片段中?哦。。。我明白了。是的,片段是一个回收视图。