CollapsingToolbarLayout正在滚动并卡住

问题描述 投票:0回答:1

我正在通过以下ScrollFlags实现CollapsingToolbarLayout

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

并且滚动过度,当我向上滚动时被卡住。仅当您使用扩展的应用栏向上滚动时,它才会发生。我认为将enterAlwaysexitUntilCollapsed结合使用会导致这种情况。如何解决此问题?

这是我的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

android android-layout android-collapsingtoolbarlayout android-appbarlayout
1个回答
0
投票

请尝试这个。我的应用程序中有折叠工具栏,可以正常工作。

<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>
© www.soinside.com 2019 - 2024. All rights reserved.