Android 工具栏没有';t在抽屉布局中滚动recyclerview时隐藏

Android 工具栏没有';t在抽屉布局中滚动recyclerview时隐藏,android,android-layout,tabs,android-collapsingtoolbarlayout,drawerlayout,Android,Android Layout,Tabs,Android Collapsingtoolbarlayout,Drawerlayout,您好,我试图隐藏工具栏时,我滚动recyclerview这是在片段,我的布局也有一个抽屉布局和表格布局。我只是想隐藏工具栏并向上移动选项卡栏 这是我的activity_main.xml <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout android:layout_width="match_parent" android:layout_height="match_

您好,我试图隐藏工具栏时,我滚动recyclerview这是在片段,我的布局也有一个抽屉布局和表格布局。我只是想隐藏工具栏并向上移动选项卡栏

这是我的activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#e9e7e7"
    tools:context=".MainActivity">



    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/cl_dashboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v4.view.ViewPager
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:id="@+id/viewPager"
            >

        </android.support.v4.view.ViewPager>



        <android.support.design.widget.AppBarLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/appBarLayout">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/ctb_dashboard"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="@color/white"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">


                <android.support.v7.widget.Toolbar
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:layout_width="match_parent"
                    android:background="@color/colorPrimary"
                    android:minHeight="?attr/actionBarSize"
                    android:id="@+id/toolBar"
                    app:layout_scrollFlags="scroll|enterAlways"
                    android:layout_height="wrap_content"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:theme="@style/ThemeOverlay.AppCompat.Dark"
                    app:layout_collapseMode="pin">

                </android.support.v7.widget.Toolbar>

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

            <android.support.design.widget.TabLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:id="@+id/tabLayout"
                app:tabMode="fixed"
                app:tabSelectedTextColor="@color/white"
                app:tabTextColor="@color/colorTab"
                app:tabTextAppearance="@style/MyTabStyle"
                app:tabIndicatorColor="@android:color/white"
                app:tabIndicatorHeight="3dp"
                app:tabGravity="fill">
            </android.support.design.widget.TabLayout>


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


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



    <android.support.design.widget.NavigationView
        app:headerLayout="@layout/header"
        app:itemTextAppearance="@style/NavDrawerTextStyle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/nav_view"
        android:background="#d2d2d2"
        app:itemTextColor="#6c6c6c"
        app:itemIconTint="#6c6c6c"
        app:menu="@menu/drawermenu"
        android:layout_gravity="start">
    </android.support.design.widget.NavigationView>




</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#e9e7e7"
    tools:context=".MainActivity">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/cl_dashboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v4.view.ViewPager
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:id="@+id/viewPager"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            >

        </android.support.v4.view.ViewPager>


        <android.support.design.widget.AppBarLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/appBarLayout">

                <android.support.v7.widget.Toolbar
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:layout_width="match_parent"
                    android:background="@color/colorPrimary"
                    android:minHeight="?attr/actionBarSize"
                    android:id="@+id/toolBar"
                    app:layout_scrollFlags="scroll|enterAlways"
                    android:layout_height="wrap_content"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:theme="@style/ThemeOverlay.AppCompat.Dark"
                    app:layout_collapseMode="pin">

                </android.support.v7.widget.Toolbar>

            <android.support.design.widget.TabLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:id="@+id/tabLayout"
                app:tabSelectedTextColor="@color/white"
                app:tabTextColor="@color/colorTab"
                app:tabTextAppearance="@style/MyTabStyle"
                app:tabIndicatorColor="@android:color/white"
                app:tabIndicatorHeight="3dp"
                app:tabMode="fixed"
                app:tabGravity="fill">
            </android.support.design.widget.TabLayout>


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

    <android.support.design.widget.NavigationView
        app:headerLayout="@layout/header"
        app:itemTextAppearance="@style/NavDrawerTextStyle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/nav_view"
        android:background="#d2d2d2"
        app:itemTextColor="#6c6c6c"
        app:itemIconTint="#6c6c6c"
        app:menu="@menu/drawermenu"
        android:layout_gravity="start">
    </android.support.design.widget.NavigationView>


</android.support.v4.widget.DrawerLayout>

fragment_home.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".HomeFragment">

    <android.support.v7.widget.RecyclerView
        android:layout_marginTop="100dp"
        android:id="@+id/blog_listt2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </android.support.v7.widget.RecyclerView>

    <ProgressBar
        android:id="@+id/progressBar2"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:indeterminateTint="@color/colorPrimaryDark"
        android:visibility="visible"/>

</FrameLayout>


我已经尝试了在Stack overflow中找到的大多数答案,但仍然无法完成。我做错什么了吗?请有人在一周内帮我解决这个问题。

你能详细说明出了什么问题吗?我在这里看到的最大问题是在折叠工具栏布局的
layout\u滚动标记上设置了
exituntilclopsed
标记。如果您无法使工具栏从屏幕上滚动,这就是罪魁祸首。您的AppBarLayout需要如下设置:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:titleEnabled="false"
        app:layout_scrollFlags="scroll">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin" />
    </android.support.design.widget.CollapsingToolbarLayout>

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
这是我找到的解释AppBarLayout和CollasingToolbarLayout的所有不同滚动标志的最佳资源:

acitivity\u main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#e9e7e7"
    tools:context=".MainActivity">



    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/cl_dashboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v4.view.ViewPager
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:id="@+id/viewPager"
            >

        </android.support.v4.view.ViewPager>



        <android.support.design.widget.AppBarLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/appBarLayout">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/ctb_dashboard"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="@color/white"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">


                <android.support.v7.widget.Toolbar
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:layout_width="match_parent"
                    android:background="@color/colorPrimary"
                    android:minHeight="?attr/actionBarSize"
                    android:id="@+id/toolBar"
                    app:layout_scrollFlags="scroll|enterAlways"
                    android:layout_height="wrap_content"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:theme="@style/ThemeOverlay.AppCompat.Dark"
                    app:layout_collapseMode="pin">

                </android.support.v7.widget.Toolbar>

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

            <android.support.design.widget.TabLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:id="@+id/tabLayout"
                app:tabMode="fixed"
                app:tabSelectedTextColor="@color/white"
                app:tabTextColor="@color/colorTab"
                app:tabTextAppearance="@style/MyTabStyle"
                app:tabIndicatorColor="@android:color/white"
                app:tabIndicatorHeight="3dp"
                app:tabGravity="fill">
            </android.support.design.widget.TabLayout>


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


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



    <android.support.design.widget.NavigationView
        app:headerLayout="@layout/header"
        app:itemTextAppearance="@style/NavDrawerTextStyle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/nav_view"
        android:background="#d2d2d2"
        app:itemTextColor="#6c6c6c"
        app:itemIconTint="#6c6c6c"
        app:menu="@menu/drawermenu"
        android:layout_gravity="start">
    </android.support.design.widget.NavigationView>




</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#e9e7e7"
    tools:context=".MainActivity">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/cl_dashboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v4.view.ViewPager
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:id="@+id/viewPager"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            >

        </android.support.v4.view.ViewPager>


        <android.support.design.widget.AppBarLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/appBarLayout">

                <android.support.v7.widget.Toolbar
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:layout_width="match_parent"
                    android:background="@color/colorPrimary"
                    android:minHeight="?attr/actionBarSize"
                    android:id="@+id/toolBar"
                    app:layout_scrollFlags="scroll|enterAlways"
                    android:layout_height="wrap_content"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:theme="@style/ThemeOverlay.AppCompat.Dark"
                    app:layout_collapseMode="pin">

                </android.support.v7.widget.Toolbar>

            <android.support.design.widget.TabLayout
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:id="@+id/tabLayout"
                app:tabSelectedTextColor="@color/white"
                app:tabTextColor="@color/colorTab"
                app:tabTextAppearance="@style/MyTabStyle"
                app:tabIndicatorColor="@android:color/white"
                app:tabIndicatorHeight="3dp"
                app:tabMode="fixed"
                app:tabGravity="fill">
            </android.support.design.widget.TabLayout>


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

    <android.support.design.widget.NavigationView
        app:headerLayout="@layout/header"
        app:itemTextAppearance="@style/NavDrawerTextStyle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/nav_view"
        android:background="#d2d2d2"
        app:itemTextColor="#6c6c6c"
        app:itemIconTint="#6c6c6c"
        app:menu="@menu/drawermenu"
        android:layout_gravity="start">
    </android.support.design.widget.NavigationView>


</android.support.v4.widget.DrawerLayout>


非常感谢您。我删除了CollasingToolbarLayout,它工作了。我当前的活动_main.xml如下所示。我可以添加一个晶圆厂并将其隐藏在卷轴上。尝试在coordinatorLayout下添加晶圆厂,但在我滚动recyclerview时它不会隐藏。