collapsingtoolbarlayout recyclerview 分开工作

collapsingtoolbarlayout recyclerview working separately

折叠工具栏布局和回收站视图应该在滑动时一起工作,但分开工作。 建议我做什么!下面给出了我的代码和我项目的 gif 部分。

如果我从下往上滑动屏幕,工具栏布局未完全显示。 工具栏布局已关闭,只有 return 如果我单独滑动到工具栏布局。

我希望工具栏布局在我上下滑动屏幕时以相同的方式排列。

我的布局代码

<?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"
    tools:context=".ui.review.reviewActivity">


    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">


        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collaps_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="true">


            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:gravity="center_vertical"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:contentDescription="TODO"
                    android:src="@drawable/cover_image"
                    app:layout_constraintTop_toTopOf="parent" />

            </androidx.constraintlayout.widget.ConstraintLayout>

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_collapseMode="parallax">

                <TextView
                    android:id="@+id/textView_title"
                    android:layout_width="wrap_content"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="130dp"
                    android:gravity="center"
                    android:maxLines="1"
                    android:text="title"
                    android:textColor="#FFF"
                    android:textSize="24sp" />

            </FrameLayout>

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/Theme.AppTheme.PopupOverlay"
                app:layout_collapseMode="parallax" />


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

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/review_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fadeScrollbars="false"
            android:scrollbars="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    </RelativeLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

最终结果

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="@+id/itineraryListFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?android:windowBackground">
    
    
    <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">
        
        
        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true">
            
            
            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:contentScrim="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways">
                
                
                <Button
                    android:id="@+id/button_arrow"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/activity_start_margin"
                    android:layout_marginTop="@dimen/_20sdp"
                    android:layout_marginEnd="@dimen/activity_end_margin"
                    android:background="@null"
                    android:clickable="true"
                    android:drawableStart="@drawable/ic_arrow_booking_details"
                    android:gravity="start|center_vertical" />
                
                
                <ImageView
                    android:id="@+id/iv_background_image"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_123sdp"
                    android:contentDescription="@string/name_app"
                    android:scaleType="centerCrop"
                    app:srcCompat="@drawable/booking_details_background" />
                
                
                <ImageView
                    android:id="@+id/iv_background_rectangle"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_123sdp"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax"
                    app:srcCompat="@drawable/rectangle_booking_details" />
                
                
                <TextView
                    android:id="@+id/tv_background_title"
                    style="@style/font_title_bookingdetails"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/activity_start_margin"
                    android:layout_marginTop="95dp"
                    android:layout_marginEnd="@dimen/activity_end_margin"
                    android:gravity="start|center_vertical"
                    android:text="@string/text_trek_everest_name"
                    android:textColor="@color/colorPrimary" />
                
                
                <androidx.constraintlayout.widget.Guideline
                    android:id="@+id/guideline9"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    app:layout_constraintGuide_begin="26dp" />
                
                
                <androidx.appcompat.widget.Toolbar
                    android:layout_width="?attr/actionBarSize"
                    android:layout_height="wrap_content"
                    app:layout_collapseMode="pin"
                    app:layout_scrollFlags="scroll|enterAlways"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
            
            
            </com.google.android.material.appbar.CollapsingToolbarLayout>
        
        
        </com.google.android.material.appbar.AppBarLayout>
        
        
        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
            
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                
                <TextView
                    android:id="@+id/tv_title_itinerary_list"
                    style="@style/font_title_day1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/activity_start_margin"
                    android:layout_marginTop="@dimen/_15sdp"
                    android:layout_marginBottom="@dimen/activity_end_margin"
                    
                    android:gravity="center_vertical"
                    android:text="@string/dashboard_itinerary"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.235" />
                
                <include layout="@layout/booking_itinerary_recyclerview" />
            </LinearLayout>
        </androidx.core.widget.NestedScrollView>
    
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</FrameLayout>

这是这段代码的输出。