首先上代码
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
app:layout_scrollFlags="scroll|enterAlways"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
app:layout_scrollFlags="scroll|enterAlways"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_centerInParent="true"
android:text="我是要隐藏的顶部标题"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:text="标题"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:text="我是中间的布局"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:paddingTop="100dp"
android:id="@+id/recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
哪个控件要隐藏就设置app:layout_scrollFlags="scroll|enterAlways"
哪个控件滑动设置 app:layout_behavior="@string/appbar_scrolling_view_behavior"(通知布局中包含滑动组件!)
scroll: 所有想滚动出屏幕的view都需要设置这个flag- 没有设置这个flag的view将被固定在屏幕顶部。
enterAlways:这个flag让任意向下的滚动都会导致该view变为可见,启用快速“返回模式”。
enterAlwaysCollapsed:当你的视图已经设置minHeight属性又使用此标志时,你的视图只能已最小高度进入,只有当滚动视图到达顶部时才扩大到完整高度。
exitUntilCollapsed: 滚动退出屏幕,最后折叠在顶端。