这个效果呢,好久之前在一些大厂App上看到过,当时想的思路是经过 ScrollView的滑动设置控件的显示隐藏android
接下来,说下CoordinatorLayout这个布局app
1.支持布局
androidx.coordinatorlayout.widget.CoordinatorLayout
若是用的不是Androidx库的话须要额为的导入 desin包google
2.使用code
个人是实现的这个效果get
总体的结构就是:string
<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.注意点it
1.由于CoordinatorLayout须要监听存在滑动的View因此须要在RecyclerView(滑动控件)中添加io
app:layout_behavior="@string/appbar_scrolling_view_behavior"
2.由于咱们须要根据滑动让ToolBar发生变化,须要让AppBarLayout进行包裹,固然功能不单单限于ToolBar,由于我就不是class
只须要将咱们想要发生变化的Layout放入AppBarLayout进行包裹就能够了,下边是咱们想要实现效果设置的样式, 不加入是没有效果的。
app:layout_scrollFlags="scroll|enterAlways"
scroll :只会把AppBarLayout顶上去,
enterAlways:会根据用户的手势,进行显示隐藏。