Панель поиска с прокруткой Material Design и RecyclerView

Я бы хотел, чтобы моя панель поиска Material Design прокручивалась/сворачивалась при прокрутке вниз в моем представлении recyclerview. Я следовал рекомендациям здесь, но не могу заставить это работать.

Моя деятельность XML:

<?xml version = "1.0" encoding = "utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    xmlns:app = "http://schemas.android.com/apk/res-auto">

    <com.google.android.material.appbar.AppBarLayout
        android:id = "@+id/appBarLayout"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "parent">

        <com.google.android.material.appbar.MaterialToolbar
            android:id = "@+id/topAppBar"
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:minHeight = "?attr/actionBarSize"
            app:title = "Test"
            app:navigationIcon = "@drawable/ic_navigate_back"/>

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

    <fragment
        android:id = "@+id/nav_host_fragment_activity_standalone"
        android:name = "androidx.navigation.fragment.NavHostFragment"
        android:layout_width = "match_parent"
        android:layout_height = "0dp"
        app:defaultNavHost = "true"
        app:layout_constraintBottom_toBottomOf = "parent"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintTop_toBottomOf = "@id/appBarLayout" />

</androidx.constraintlayout.widget.ConstraintLayout>

Мой фрагмент 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"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent">

    <!-- NestedScrollingChild goes here (NestedScrollView, RecyclerView, etc.). -->
    <androidx.recyclerview.widget.RecyclerView
        android:id = "@+id/recUserlist"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        android:layout_marginStart = "16dp"
        android:layout_marginEnd = "16dp"
        android:orientation = "vertical"
        app:layout_behavior = "@string/appbar_scrolling_view_behavior"
        app:layoutManager = "androidx.recyclerview.widget.LinearLayoutManager" />

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:fitsSystemWindows = "true"
        android:backgroundTint = "@color/surface_900">
        <com.google.android.material.search.SearchBar
            android:id = "@+id/search_bar"
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:hint = "Username" />
    </com.google.android.material.appbar.AppBarLayout>

    <com.google.android.material.search.SearchView
        android:id = "@+id/searchview"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        android:hint = "Username"
        app:layout_anchor = "@id/search_bar">
        <androidx.recyclerview.widget.RecyclerView
            android:id = "@+id/recFilteredUserlist"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent"
            android:orientation = "vertical"
            app:layoutManager = "androidx.recyclerview.widget.LinearLayoutManager" />
    </com.google.android.material.search.SearchView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

SearchBar не прокручивается при прокрутке вниз по recyclerview, если только recyclerview не вложен внутри NestedScrollView. Однако я хотел бы избежать помещения моего представления recyclerview во вложенное представление прокрутки, поскольку это вызывает проблемы с производительностью: все элементы recyclerview будут привязаны/отрисованы одновременно.

Что мне здесь не хватает?

1
0
118
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Проблема была решена путем изменения значения NestedScrollingenabled с false на true в представлении recyclerview.

Другие вопросы по теме