CoordinatorLayout 滚动不起作用,除非工具栏有 layout_scrollflags:scroll

CoordinatorLayout scroll doesn't work unless Toolbar has layout_scrollflags:scroll

我正在尝试让 AppBarLayout 仅滚动其子项之一,而不滚动其中的 ToolBar。

但是,当我从工具栏中删除 layout_scrollflags=scroll 时,没有任何滚动。

是否可以在 AppBarLayout 滚动中只有一个视图而不是工具栏?

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


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

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?actionBarSize"
                    android:theme="@style/BarTheme"
                    app:title="@string/my">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center|start"
                        android:src="@{ViewModel.showingDropdown ? @drawable/ic_arrow_drop_up_white_24dp : @drawable/ic_arrow_drop_down_white_24dp}"
                        android:tint="@color/ring_blue"
                        android:visibility="@{ViewModel != null ? View.VISIBLE : View.GONE}" />
                </android.support.v7.widget.Toolbar>

                <FrameLayout
                    android:id="@+id/widget_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:layout_scrollFlags="scroll|enterAlways" />
            </android.support.design.widget.AppBarLayout>

该代码的结果是没有滚动,但是当我将 layout_scrollflags=scroll 添加到工具栏时,Toolbar 和 FrameLayout 都滚动,这是我不想要的

为此使用折叠工具栏布局...并使工具栏 collapse_mode = "pin" 和其他 collapse_mode = parallax 您想要滚动的布局参考检查 https://antonioleiva.com/collapsing-toolbar-layout/

  • 保持折叠的父布局 工具栏布局为 appBarlayout..

  • 为其分配滚动标志..

  • 定义折叠工具栏布局的子布局及其所需的collapse_modes(视差、pin..等)