滚动RecyclerView时无法隐藏工具栏,可能的原因是什么?

时间:2016-11-25 09:32:01

标签: android xml android-recyclerview android-coordinatorlayout

我试图在ToolBar滚动时隐藏RecyclerView,但ToolBar根本不隐藏或移动。这就是我实现它的方式:

<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:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:background="?colorPrimary"
    android:elevation="@dimen/margin_8"
    android:layout_width="match_parent"
    android:id="@+id/appbar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        app:layout_scrollFlags="scroll|enterAlways"
        android:layout_marginLeft="@dimen/list_toolbar_side_margin"
        android:layout_marginRight="@dimen/list_toolbar_side_margin"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="?attr/colorPrimary">

        <TextView
            android:id="@+id/titleText"
            android:text="@string/app_name"
            android:gravity="start|center"
            android:textSize="19sp"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >


        <android.support.v7.widget.RecyclerView
            android:id="@+id/homeTeamRView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:scrollbarStyle="outsideOverlay"
            android:paddingLeft="@dimen/list_side_margin"
            android:paddingRight="@dimen/list_side_margin"
            android:paddingBottom="@dimen/margin_16" />

</FrameLayout>

如何解决?

2 个答案:

答案 0 :(得分:0)

要解决此问题,请添加Toolbar小部件(android.support.v7.widget.Toolbar):

 app:layout_scrollFlags="scroll|enterAlways"

答案 1 :(得分:0)

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:layout_scrollFlags="scroll|enterAlways"
       />

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

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

如上所述