CollapsingToolbarLayout закончен, прокрутка и застрял - PullRequest
0 голосов
/ 05 ноября 2019

Я реализую CollapsingToolbarLayout со следующими ScrollFlags

app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed|snap"

, и при прокрутке вверх прокручивается и застревает. Это происходит только тогда, когда вы прокручиваете вверх с расширенной панелью приложений. Я думаю, что сочетание enterAlways и exitUntilCollapsed вызывает это. Как решить эту проблему?

Вот мой макет xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ScrollingActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:expandedTitleMarginTop="0dp"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed|snap"
            app:toolbarId="@+id/toolbar">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:minHeight="?attr/actionBarSize"
                android:layout_gravity="top"
                app:layout_collapseMode="pin"
                app:title="App Title"
                app:popupTheme="@style/AppTheme.PopupOverlay">

            </androidx.appcompat.widget.Toolbar>

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

    <include layout="@layout/content_scrolling" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Заранее спасибо enter image description here

1 Ответ

0 голосов
/ 05 ноября 2019

Вы должны попробовать без атрибута snap в scrollFlags, а также удалить min__height из Toolbar, поскольку в вашем случае это не требуется.

Пожалуйста, попробуйте это. В моем приложении отлично работает сворачивающаяся панель инструментов.

<com.google.android.material.appbar.AppBarLayout 
    ...
    app:liftOnScroll="true">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed"
        app:scrimAnimationDuration="0"
        app:statusBarScrim="@color/colorPrimary"
        app:titleEnabled="false">

        <!-- </CollapsingViews> -->

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:focusableInTouchMode="true"
            android:theme="@style/ToolbarTheme"
            app:collapseIcon="@drawable/ic_arrow_back_search"
            app:contentInsetEnd="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetRight="0dp"
            app:contentInsetStart="0dp"
            app:contentInsetStartWithNavigation="0dp"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </com.google.android.material.appbar.CollapsingToolbarLayout>

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