【问题标题】:CoordinatorLayout scroll doesn't work unless Toolbar has layout_scrollflags:scroll除非 Toolbar 具有 layout_scrollflags:scroll,否则 CoordinatorLayout 滚动不起作用
【发布时间】:2018-02-15 19:26:51
【问题描述】:

我试图让 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 添加到工具栏时,工具栏和 FrameLayout 都会滚动,这是我不想要的

【问题讨论】:

    标签: android android-coordinatorlayout


    【解决方案1】:

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

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

    • 为其分配滚动标志..

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

    【讨论】:

    • 看起来这对我来说是可行的,但需要更多的hacky。当我使用 CollapsingToolbarLayout 时,由于它是 FrameLayout,因此内部的视图相互堆叠。为了解决这个问题,我制作了我确实想要移动带有顶部工具栏大小的空视图的 LinearLayout 的视图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多