滚动时,我在隐藏工具栏时遇到问题。我有两个布局,我将在这里展示。我将appBar和ViewPager包装在LinearLayout中,因此ViewPager完全适合屏幕。我想实现Google Material Design Guidelines并在滚动ViewPager时隐藏工具栏(其中包含RecyclerView)并让TabLayout保留在屏幕上。我认为主要问题可能是LinearLayout,但是当我不使用它时它也不起作用。此外,当我滚动时FAB不会隐藏,它是我想要制作的另一个动画。
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>
感谢您的帮助