Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 工具栏未隐藏在RecyclerView滚动条上_Android_Android Recyclerview_Android Toolbar - Fatal编程技术网

Android 工具栏未隐藏在RecyclerView滚动条上

Android 工具栏未隐藏在RecyclerView滚动条上,android,android-recyclerview,android-toolbar,Android,Android Recyclerview,Android Toolbar,我正试图使我的应用程序中的工具栏基于回收视图的滚动隐藏和显示。这个gif显示了我正在努力实现的目标 我在跟踪,没有得到我想要的结果。以下是我的活动布局: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:

我正试图使我的应用程序中的
工具栏基于
回收视图的滚动隐藏和显示。这个gif显示了我正在努力实现的目标

我在跟踪,没有得到我想要的结果。以下是我的活动布局:

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:fitsSystemWindows="true">

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/toolbar" />

</android.support.design.widget.AppBarLayout>

<FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF" />

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/header"
    app:menu="@menu/drawer" />

</android.support.design.widget.CoordinatorLayout>

当我运行此代码时,
工具栏
完全消失。怎么了?

如果您的
RecyclerView
位于片段内部,请尝试将以下代码放在片段布局的根视图中:
app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
。包含的视图必须是@orret3所述的
协调布局的直接子视图

 app:layout_behavior="@string/appbar_scrolling_view_behavior"
到您的容器
FrameLayout
,如下所示

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


我假设回收视图是这个容器的子对象。

您需要执行两个操作:

  • 从工具栏xml中删除此行:

    app:layout_scrollFlags=“scroll | enterally”

  • 和其他答案一样,将这一行添加到包装片段的布局中 (在您的情况下是框架布局)

    app:layout_behavior=“@string/appbar_scrolling_view_behavior”


  • 看看这个,我想学习第3部分教程,因为我很快就会实现一个晶圆厂@这里是SanketKachhelaSame。我在我的应用程序中有几乎相同的结构,并遵循相同的教程,但工具栏不会隐藏在滚动条上。如果我能解决这个问题,我会让你知道我也有同样的问题。有人解决了吗?@bashan我设法解决了这个问题,并在另一个线程中转移到另一个问题上,但我不记得这是怎么回事,因为这是很久以前的事了。不过这可能会有帮助,看看吧
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF" 
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>