Android 如何不以编程方式完全折叠折叠工具栏布局?

Android 如何不以编程方式完全折叠折叠工具栏布局?,android,android-collapsingtoolbarlayout,Android,Android Collapsingtoolbarlayout,我在AppBarLayout中有折叠工具栏布局。在折叠工具栏布局内部我有一个带有应用程序的工具栏:layout\u collapseMode=“pin”。 我有RecyclerView。当我滚动RecyclerViewmyCollavingToolbarLayout时,首先折叠到工具栏的大小。然后它就完全崩溃了。 要显示我制作的gif的行为: 我有三种折叠工具栏布局状态: 1) 完全扩展 2) 折叠为工具栏大小 3) 完全崩溃 如果我使用折叠工具栏布局的setExpanded方法,我可以

我在
AppBarLayout
中有
折叠工具栏布局
。在
折叠工具栏布局内部
我有一个带有
应用程序的工具栏:layout\u collapseMode=“pin”
。 我有
RecyclerView
。当我滚动
RecyclerView
my
CollavingToolbarLayout
时,首先折叠到工具栏的大小。然后它就完全崩溃了。
要显示我制作的gif的行为:

我有三种折叠工具栏布局状态:

1) 完全扩展

2) 折叠为工具栏大小

3) 完全崩溃

如果我使用
折叠工具栏布局的
setExpanded
方法,我可以完全折叠完全展开状态

我想知道如何通过编程方式将
折叠工具栏布局
折叠为工具栏大小(我在屏幕截图中显示了折叠为工具栏大小

我的布局:

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

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="150dp">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleGravity="start|center_vertical"
                app:layout_scrollFlags="scroll|snap|enterAlways"
                app:title="">

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>

使用可以使用
应用程序:布局

app:layout_scrollFlags=“scroll | exituntilclopsed | snap”

在您的

此处的完整代码:

  <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleGravity="start|center_vertical"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="">

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


在滚动时,您希望工具栏有什么?当前的行为对我很好。它必须像现在一样工作。但我需要编程能力(无需用户交互)将工具栏布局折叠到工具栏大小(我在屏幕截图中显示为折叠到工具栏大小)。你想自动滚动到顶部吗?@AntonI需要在某些情况下以编程方式获得图像中的状态。我尝试你的建议。但如果我添加ExitUntil,当我滚动recyclerview时,我的工具栏不会隐藏。