这个效果呢,很久以前在一些大厂App上看到过,当时想的思路是通过 ScrollView的滑动设置控件的显示隐藏
接下来,说下CoordinatorLayout这个布局
1.支持
androidx.coordinatorlayout.widget.CoordinatorLayout
如果用的不是Androidx库的话需要额为的导入 desin包
2.使用
我的是实现的这个效果
整体的结构就是:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
app:layout_scrollFlags="scroll|enterAlways">
..........内容过多
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/vindicate_detail_rcy"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
3.注意点
1.因为CoordinatorLayout需要监听存在滑动的View所以需要在RecyclerView(滑动控件)中添加
app:layout_behavior="@string/appbar_scrolling_view_behavior"
2.因为我们需要根据滑动让ToolBar发生变化,需要让AppBarLayout进行包裹,当然功能不仅仅限于ToolBar,因为我就不是
只需要将我们想要发生变化的Layout放入AppBarLayout进行包裹就可以了,下边是我们想要实现效果设置的样式, 不加入是没有效果的。
app:layout_scrollFlags="scroll|enterAlways"
scroll :只会把AppBarLayout顶上去,
enterAlways:会根据用户的手势,进行显示隐藏。