Android 折叠工具栏布局不';不要把任何东西折叠起来

Android 折叠工具栏布局不';不要把任何东西折叠起来,android,android-fragments,android-recyclerview,android-collapsingtoolbarlayout,Android,Android Fragments,Android Recyclerview,Android Collapsingtoolbarlayout,当我在回收器视图片段中上下滚动时,我想隐藏和显示工具栏,但CollasingToolbarLayout并没有完成它应该做的事情 首先,我尝试只使用协调器布局,但它没有折叠工具栏布局那么流畅(当它工作时) 是因为回收器视图位于片段中吗?到底是什么问题 主要布局: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.

当我在回收器视图片段中上下滚动时,我想隐藏和显示工具栏,但CollasingToolbarLayout并没有完成它应该做的事情

首先,我尝试只使用协调器布局,但它没有折叠工具栏布局那么流畅(当它工作时)

是因为回收器视图位于片段中吗?到底是什么问题

主要布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">

<android.support.design.widget.CoordinatorLayout
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.github.mpivchev.app.activities.MainActivity">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="2dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <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/ThemeOverlay.AppCompat.Light"
                    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                        <Spinner
                            android:id="@+id/spinner"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="8dp"
                            android:gravity="start"
                            android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                            android:spinnerMode="dialog" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_alignParentStart="true"
                            android:layout_centerVertical="true"
                            android:fontFamily="@font/roboto"
                            android:paddingTop="18dp"
                            android:text="TestString" />
                    </RelativeLayout>

                </android.support.v7.widget.Toolbar>
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>

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

<android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/main_drawer" />

片段布局的一部分:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

...

</android.support.constraint.ConstraintLayout>

...

您的工具栏没有定义的collapseMode,因此没有说明它应该如何工作。将app:collapseMode=“pin”添加到工具栏xml中。

您的工具栏没有定义的collapseMode,因此没有说明它应该如何工作。将app:collapseMode=“pin”添加到您的工具栏xml。

@Milen重新阅读您的问题-我假设您说的是工具栏没有崩溃。只是想确定我看到的是正确的问题。这就是你所说的不做它应该做的事情的意思吗?@Milen在读你的问题时——我想你是说工具栏没有崩溃。只是想确定我看到的是正确的问题。这就是你所说的不做该做的事的意思吗?