【发布时间】:2019-02-22 12:31:29
【问题描述】:
当用户滚动 recyclerView 时,我在尝试隐藏工具栏时遇到了一些麻烦。
工具栏是透明的并且在recyclerView之上(通过FrameLayout)。我进行了很多搜索,但没有找到解决此错误行为的任何解决方案。
目前,我有这个 xml:
<android.support.design.widget.CoordinatorLayout 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"
app:statusBarBackground="@android:color/transparent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:fitsSystemWindows="true">
<include layout="@layout/toolbar_activity" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
使用此代码,工具栏固定在顶部,不受 app:layout_behavior="@string/appbar_scrolling_view_behavior" 的影响。我已经尝试将该属性移动到 FrameLayout,但在这种情况下,recyclerview 位于工具栏下方,而不是其后面。
知道如何解决这个问题吗?我要疯了……
【问题讨论】:
-
为什么需要
Framelayout?使用RecyclerView直接 -
去掉FrameLayout,recyclerview出现在Toolbar下方
标签: android android-recyclerview android-coordinatorlayout android-appbarlayout