Android CoordinatorLayout + TabLayout + ViewPager Toolbar not hidding on scroll

依然范特西╮ 提交于 2019-12-11 05:18:46

问题


I'm having a problem hidding the Toolbar when I scroll. I have two layouts that I'll show here. I have the appBar and ViewPager wrapped inside a LinearLayout so the ViewPager fits entirely in the screen. I want to implement the Google Material Design Guidelines and hide the Toolbar when I scroll the ViewPager (it contains a RecyclerView in it) and let the TabLayout stay on the screen. I think the main problem may be the LinearLayout, but when I'm not using it it doesn't work also. Also, the FAB doesn't hide when I scroll and it's another animation that I want to produce.

skeleton_view.xml

    <android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/appbarlayout">
    <android.support.v7.widget.Toolbar
        android:id="@+id/tool_bar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/colorTeal200"
        app:popupTheme="@style/AppTheme"
        android:elevation="6dp"
        app:layout_scrollFlags="scroll|enterAlways"/>

    <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="52dp"
        app:tabGravity="fill"
        app:tabMode="fixed"
        android:layout_gravity="bottom"
        android:background="@color/colorText"
        app:tabIndicatorColor="@color/colorTeal500"
        android:id="@+id/tab_layout"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/gallery_fab"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="160dp"
    android:layout_marginBottom="16dp"
    android:src="@drawable/ic_photo_library_white_24px"
    app:backgroundTint="@color/colorAccent700"
    app:borderWidth="0dp"
    app:elevation="12dp"
    app:pressedTranslationZ="12dp"
    android:visibility="invisible"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/camera_fab"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="90dp"
    android:layout_marginBottom="16dp"
    android:src="@drawable/ic_camera_alt_white_24px"
    app:backgroundTint="@color/colorAccent700"
    app:borderWidth="0dp"
    app:elevation="12dp"
    app:pressedTranslationZ="12dp"
    android:visibility="invisible"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/floating_button"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_margin="16dp"
    android:src="@drawable/ic_add_white_24px"
    app:backgroundTint="@color/colorAccent700"
    app:borderWidth="0dp"
    app:elevation="12dp"
    app:layout_behavior="com.draft.meal.testing.ScrollFABAction.ScrollOffBottomBehaviour"
    app:layout_anchorGravity="bottom|right|end"
    app:layout_anchor="@id/view_pager"/>

skeleton.xml

    <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:id="@+id/nav_drawer"
    android:layout_alignParentRight="true"
    android:fitsSystemWindows="true"
    android:elevation="7dp"
    tools:openDrawer="end"
    android:gravity="left"
    android:layout_gravity="end">

    <include layout="@layout/skeleton_view"/>

    <android.support.design.widget.NavigationView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/navigation_view"
        android:layout_gravity="end"
        android:gravity="left"
        app:headerLayout="@layout/navigation_header"
        app:elevation="4dp"
        app:menu="@menu/drawer">
    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

Thanks for the help

来源:https://stackoverflow.com/questions/36896082/android-coordinatorlayout-tablayout-viewpager-toolbar-not-hidding-on-scroll

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