首页 > 解决方案 > 向上滚动时显示工具栏 - 具有多个捕捉点的 CoordinatorLayout

问题描述

我正在使用这种技术在折叠工具栏上创建多个捕捉点(我使用相同的布局和代码)

但我的问题是当用户在 recyclerview 中间向上滚动时如何显示工具栏

目前,如果用户到达顶部,它首先显示工具栏,然后展开折叠工具栏

但是我想在用户在 recyclerview 中间向上滚动时(在到达顶部之前)显示工具栏,之后,如果用户到达顶部,我想展开折叠布局。

我怎样才能修改那个答案来实现呢?

目前它看起来像这样。如果用户到达顶部,我只想在用户向上滚动时显示工具栏我想显示所有折叠的工具栏

在此处输入图像描述

我的 AppBarLayout

        <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/app_bar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:background="@color/colorPrimary"
                app:elevation="0dp"
                android:elevation="0dp">


            <com.google.android.material.appbar.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    app:layout_scrollFlags="scroll|snap"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginStart="@dimen/app_bar_expanded_title_margin_start">

                <LinearLayout
                        android:id="@+id/expanded_layout"
                        android:visibility="visible"
                        android:layout_width="match_parent"
                        android:layout_height="200dp"
                        android:layout_marginBottom="?attr/actionBarSize"
                        android:orientation="vertical">


                </LinearLayout>

            </com.google.android.material.appbar.CollapsingToolbarLayout>

            <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="90dp"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    android:layout_gravity="bottom"
                    app:layout_collapseMode="pin"
                    android:contentInsetLeft="0dp"
                    android:contentInsetStart="0dp"
                    app:contentInsetLeft="0dp"
                    app:contentInsetStart="0dp"
                    android:contentInsetRight="0dp"
                    android:contentInsetEnd="0dp"
                    app:contentInsetRight="0dp"
                    app:contentInsetEnd="0dp">
                <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">
                ...
                </LinearLayout>
            </androidx.appcompat.widget.Toolbar>

            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="?actionBarSize"
                    android:layout_marginStart="@dimen/general_margin"
                    android:orientation="horizontal">


                <CustomTabLayout
                        android:id="@+id/tab_layout"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/discover_tab_height"
                        android:background="@color/colorPrimary"
                        android:paddingEnd="@dimen/general_margin"
                        android:layout_gravity="center"
                        android:clipToPadding="false"
                        app:tabMode="scrollable"
                        app:tabGravity="fill"
                        app:tabBackground="@drawable/discover_tab_selector"
                        android:elevation="@dimen/tab_layout_elevation"
                        app:tabSelectedTextColor="@color/colorPrimary"
                        app:tabTextColor="@color/colorAccentPassive"
                        app:tabRippleColor="@null"
                        app:tabIndicatorHeight="0dp"
                        app:tabMinWidth="30dp"
                        app:tabIndicatorColor="@color/transparent"
                        app:tabTextAppearance="@style/DiscoverTabTextAppearance"/>
            </LinearLayout>

        </com.google.android.material.appbar.AppBarLayout>

请检查 具有多个捕捉点的链接 CoordinatorLayout

谢谢你,对不起我的英语。

标签: androidandroid-layoutandroid-coordinatorlayout

解决方案


推荐阅读