CollapsingToolbarLayout中的选项卡重叠RecyclerView [英] Tabs in CollapsingToolbarLayout overlapping RecyclerView
问题描述
我有一个TabLayout,其中有一个ViewPager,可以在两个片段之间进行选择,而这两个片段都具有垂直滚动的RecyclerViews.我有一个滚动的TabLayout,以便在滚动RecyclerView时,这些选项卡消失.但是,它的开始是TabLayout与RecyclerView的第一项重叠,从而将其删除.我曾尝试向ViewPager添加页边距,但是即使在选项卡已滚动出屏幕后,此页边距仍然存在.如何更改它,以使选项卡不与RecyclerView的第一项重叠?
I have a TabLayout which has a ViewPager that selects between two fragments which both have vertical scrolling RecyclerViews. I have a scrolling TabLayout so that when I scroll the RecyclerView, the tabs disappear. However, it starts off with the TabLayout overlapping the RecyclerView's first item, cutting it off. I have tried adding margin to the ViewPager but this margin exists even after the tabs have been scrolled off of the screen. How could I change it so the tabs do not overlap the first item of the RecyclerView?
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabPadding="5dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
推荐答案
将layout_behavior
添加到视图分页器
<android.support.v4.view.ViewPager
android:id="@+id/id_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
这篇关于CollapsingToolbarLayout中的选项卡重叠RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!