Android TabLayout位于Framelayout的内容下
我有一个框架布局,其中包括一个TabLayout和一个ViewPager。显然,ViewPager加载了一个片段。现在的问题是,TabLayout在加载时位于fragment的内容之下,因此消失了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="
<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现在停留在顶部。。。有没有办法解决这个问题?典型的设计模式是让选项卡保持在顶部,但是您的滚动视图是否在查看页面的片段中?哦。。。我明白了。是的,片段是一个回收视图。