Скрывать и показывать View элементы при пролистывании RecyclerView
Есть вот такая разметка, я убрал некоторые элементы.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/root_container"
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="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/headerContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/search"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:inputType="text"/>
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:src="@drawable/next" />
</LinearLayout>
<LinearLayout
android:id="@+id/musicCategoriesParent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerMusicCategories"
android:layout_width="match_parent"
android:layout_height="56dp"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingBottom="16dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/dataParent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/containerData"
android:layout_width="match_parent"
android:layout_height="match_parent">
<MusicPlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/playerView">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/musicList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:scrollbars="none" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</LinearLayout>
Хотелось бы добавить скрытие и показ отдельных ViewGroup при скроле musicList.
Думаю хороший вариант это CoordinatorLayout.Behavior, как с этим работать?
Например есть нексколько кейсов:
Скрыть headerContainer когда пользователь начинает скролить вниз (к концу списка)
Показать headerContainer когда пользователь начинает скролить вверх (к началу списка).
Список может быть из двух элементов, и скрол может быть недоступен, в таком случае нам нужно показать headerContainer сразу либо при
overScrollingСкрыть musicCategoriesParent когда пользователь начинает скролить вниз (к концу списка)
Показать musicCategoriesParent когда пользователь проскролил в самое начало