Tabs in CollapsingToolbarLayout overlapping RecyclerView

人盡茶涼 提交于 2019-12-11 16:32:55

问题


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>


回答1:


add layout_behavior to your view pager

<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" />


来源:https://stackoverflow.com/questions/49633023/tabs-in-collapsingtoolbarlayout-overlapping-recyclerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!