RecycleView 如何在滚动时隐藏显示顶部视图(不是工具栏)

RecycleView how to hide a reveal a top view on scroll (not the toolbar)

我正在尝试(受 https://mzgreen.github.io/2015/02/28/How-to-hideshow-Toolbar-when-list-is-scrolling(part2) 启发)在我向上滚动时隐藏我在 RecycleView 顶部的视图,并在向下滚动时显示它。

但是好像效果不是很好。当我向上滚动时,TextView 确实消失了,但它从顶部到列表视图的开头留下了空白 space。 (在下面的例子中,我在 textView

上使用 .setTransalteX(dy)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
       xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/test"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

我应该使用什么样的布局来存档,而不是在我向上滚动时留下空白 space,列表采用文本视图的 space?

(执行此操作的应用示例是 Booking.com 的结果列表) (向下滚动时它不会重新出现,但这很好..当列表向上滚动时搜索过滤器向上滚动的事实)

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:paddingTop="44dp"
        android:cliptoPadding="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <TextView
       xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/test"
        android:layout_width="fill_parent"
        android:layout_height="44dp" />
</LinearLayout>