使用Google默认提供的design包中的控件CoordinatorLayout和AppBarLayout即可快速实现。布局代码如下:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F6F7F8">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F6F7F8"
app:elevation="0dp">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#46ED84"
android:gravity="center"
android:text="头部滚动部分"
app:layout_scrollFlags="scroll"/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FFDB87"
android:gravity="center"
android:text="悬停部分"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvAllFiles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_12"
android:layout_marginEnd="@dimen/dp_12"
android:layout_marginBottom="@dimen/dp_26"
android:background="@drawable/shape_bg_white_5_bottom"
android:overScrollMode="never"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
需要注意的是: