Java 折叠工具栏滚动片段中的recyclerview时布局未折叠

Java 折叠工具栏滚动片段中的recyclerview时布局未折叠,java,android,Java,Android,我有一个导航活动,有一个坐标布局,包含一个折叠的AppBar布局、一个bottomNavigationView和一个片段。我正在使用NavigationUI来管理所有这些事情。当我使用recyclerview和scroll进入一个片段时,底部的导航视图会完全消失,但顶部的折叠AppBarLayout什么也不做 我在4小时的StackOverflow搜索中尝试了大约10亿种方法,但似乎都不管用。我使用的是NavigationUI、数据绑定和材质组件,但它们似乎无法协同工作 以下是我的导航活动: &

我有一个导航活动,有一个坐标布局,包含一个折叠的AppBar布局、一个bottomNavigationView和一个片段。我正在使用NavigationUI来管理所有这些事情。当我使用recyclerview和scroll进入一个片段时,底部的导航视图会完全消失,但顶部的折叠AppBarLayout什么也不做

我在4小时的StackOverflow搜索中尝试了大约10亿种方法,但似乎都不管用。我使用的是NavigationUI、数据绑定和材质组件,但它们似乎无法协同工作

以下是我的导航活动:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:id="@+id/godLayout"
    android:layout_height="match_parent">


    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/nav_graph"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="56dp">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"/>

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

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


    <com.google.android.material.bottomnavigation.BottomNavigationView
        style="@style/Widget.MaterialComponents.BottomNavigationView"
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:itemIconTint="@drawable/bottom_navigation_colors"
        app:itemTextColor="@drawable/bottom_navigation_colors"
        app:itemRippleColor="@color/color_secondary_variant"
        app:menu="@menu/bottom_navigation_menu"
        app:hideOnScroll="true"
        app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

以下是带有RecyclerView的片段:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>
        <variable
            name="isLoading"
            type="boolean" />
    </data>


    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:refreshing="@{isLoading}">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/alarm_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            app:visibleGone="@{!isLoading}" />

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>



</layout>

以下是初始化导航控制器的相关代码:

Set<Integer> topLevelDestinations = new HashSet<>();
        topLevelDestinations.add(R.id.dashboardFragment);
        topLevelDestinations.add(R.id.settingsFragment);
        topLevelDestinations.add(R.id.alarmsFragment);
        topLevelDestinations.add(R.id.vulnerabilitiesFragment);


        Toolbar toolbar = findViewById(R.id.toolbar);
        CollapsingToolbarLayout layout = findViewById(R.id.collapsing_toolbar_layout);
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(topLevelDestinations)
                .build();

        layout.setTitle("dsljasonjda");
        NavigationUI.setupWithNavController(layout, toolbar, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(bottomNavigationView, navController);
Set-topLevelDestinations=new HashSet();
添加(R.id.dashboardFragment);
topLevelDestinations.add(R.id.settingsFragment);
topLevelDestinations.add(R.id.alarmsFragment);
topLevelDestinations.add(R.id.VulnerabilityFragment);
Toolbar Toolbar=findviewbyd(R.id.Toolbar);
CollasingToolbarLayout布局=findViewById(R.id.Collasing\u toolbar\u布局);
AppBarConfiguration AppBarConfiguration=新建AppBarConfiguration.Builder(topLevelDestinations)
.build();
layout.setTitle(“dsljasonjda”);
NavigationUI.setupWithNavController(布局、工具栏、navController、appBarConfiguration);
NavigationUI.setupWithNavController(bottomNavigationView,navController);

我完全无法理解这一点,提前感谢您的帮助

如果我没有错,您应该使用NestedScrollView:示例 在片段内部有三个片段,每个片段都有一个recyclerview和其他元素


如果我没说错,您应该使用NestedScrollView:示例 在片段内部有三个片段,每个片段都有一个recyclerview和其他元素


        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:fitsSystemWindows="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent">

            <androidx.appcompat.widget.LinearLayoutCompat
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <fragment
                    android:id="@+id/nav_host_fragment_container"
                    android:name="androidx.navigation.fragment.NavHostFragment"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:defaultNavHost="true"
                    app:navGraph="@navigation/nav_home_store" />

            </androidx.appcompat.widget.LinearLayoutCompat>

        </androidx.core.widget.NestedScrollView>

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="280dp"
            app:liftOnScroll="false">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:id="@+id/ctlHomeStore"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:contentScrim="@color/green_00856A"
                app:expandedTitleGravity="top"
                app:expandedTitleMarginStart="@dimen/size_16dp"
                app:expandedTitleMarginTop="@dimen/size_40dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:scrimAnimationDuration="100">


                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/green_00856A">

                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/txvDeliveryIn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="@dimen/size_16dp"
                        android:layout_marginBottom="@dimen/size_10dp"
                        android:background="?attr/selectableItemBackground"
                        android:drawablePadding="@dimen/size_5dp"
                        android:fontFamily="@font/source_sans_pro_regular"
                        android:text="Entrega en Bogotá"
                        android:textColor="@color/white"
                        android:textSize="@dimen/size_15sp"
                        android:typeface="normal"
                        app:drawableEndCompat="@drawable/flechaderblanca"
                        app:drawableStartCompat="@drawable/ic_location"
                        app:layout_collapseMode="parallax"
                        app:layout_constraintBottom_toTopOf="@+id/txvNextTime"
                        app:layout_constraintStart_toStartOf="parent" />

                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/txvNextTime"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="@dimen/size_16dp"
                        android:layout_marginBottom="140dp"
                        android:background="?attr/selectableItemBackground"
                        android:drawablePadding="@dimen/size_5dp"
                        android:fontFamily="@font/source_sans_pro_regular"
                        android:text="Próximo horario de entrega: Mañana"
                        android:textColor="@color/white"
                        android:textSize="@dimen/size_15sp"
                        android:typeface="normal"
                        app:drawableStartCompat="@drawable/ic_calendar"
                        app:layout_collapseMode="parallax"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintStart_toStartOf="parent" />

                    <androidx.appcompat.widget.AppCompatImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom"
                        android:scaleType="fitXY"
                        app:layout_collapseMode="parallax"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:srcCompat="@drawable/bg_store" />

                    <androidx.appcompat.widget.AppCompatImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|end"
                        android:layout_marginEnd="@dimen/size_16dp"
                        android:layout_marginBottom="60dp"
                        android:scaleType="fitXY"
                        app:layout_collapseMode="parallax"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:srcCompat="@drawable/ic_truck" />

                </androidx.constraintlayout.widget.ConstraintLayout>

                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/tbHomeStore"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_marginBottom="?actionBarSize"
                    app:layout_collapseMode="pin" />

                <RelativeLayout
                    android:id="@+id/rlContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tbHomeStore"
                    android:layout_gravity="bottom"
                    android:padding="@dimen/size_16dp">

                    <com.google.android.material.textview.MaterialTextView
                        android:id="@+id/txvSearch"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/size_40dp"
                        android:background="@drawable/bg_corner_radius_home_store_white"
                        android:drawablePadding="@dimen/size_10dp"
                        android:hint="@string/title_search_home_store"
                        android:padding="@dimen/size_10dp"
                        android:textAlignment="textStart"
                        android:textColorHint="@android:color/darker_gray"
                        app:drawableStartCompat="@drawable/ic_search_green" />
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/rlContainer"
                    android:layout_gravity="end"
                    app:layout_collapseMode="pin">

                    <androidx.appcompat.widget.AppCompatImageView
                        android:id="@+id/cvCartIcon"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="end"
                        android:layout_marginTop="@dimen/size_15dp"
                        android:layout_marginEnd="@dimen/size_8dp"
                        app:layout_collapseMode="pin"
                        app:srcCompat="@drawable/ic_menu_cart" />
                </RelativeLayout>

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

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

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bnvHomeStore"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_marginStart="0dp"
            android:layout_marginEnd="0dp"
            app:itemIconTint="@drawable/selector_bottom_nav"
            app:itemTextColor="@drawable/selector_bottom_nav"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:menu="@menu/bottom_nav_menu" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>