【发布时间】:2026-01-31 00:00:01
【问题描述】:
我试图(受https://mzgreen.github.io/2015/02/28/How-to-hideshow-Toolbar-when-list-is-scrolling(part2) 启发)在向上滚动时隐藏我在 RecycleView 顶部的视图,并在向下滚动时显示它。
但它似乎不太好用。当我向上滚动时,TextView 确实消失了,但它从顶部到列表视图的开头留下了一个空白区域。 (在下面的情况下,我在 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>
我应该使用什么样的布局来归档相同的内容,而不是在我向上滚动时留下空白区域,列表会占用 textview 的空间?
(执行此操作的应用示例是 Booking.com 的结果列表) (向下滚动时它不会重新出现,但这很好..当列表向上滚动时搜索过滤器向上滚动的事实)
【问题讨论】:
标签: android view scroll hide android-recyclerview