CollapsingToolbar + RecyclerView + NavigationDrawer (это еще возможно?) - PullRequest
0 голосов
/ 03 марта 2020

Я пытаюсь реализовать сворачивающуюся панель инструментов с NavigationView & RecyclerView, но независимо от того, как далеко в пределах прокрутки RecyclerView I, Toolbar просто не рухнет! По состоянию на весну 2020 года это возможно вообще? Я действительно ненавижу растягивать большой палец, чтобы добраться до нескольких верхних элементов моего RecyclerView, поскольку размер экрана уже большой + Я не хочу использовать обе руки для прокрутки RecyclerView. Обратите внимание: если для этого нет подходящего рабочего решения, у меня не останется другого выбора, кроме как неохотно go вернуться к исходному Toolbar

Родительский макет

<?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:id="@+id/myCoordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <androidx.drawerlayout.widget.DrawerLayout
            android:id="@+id/myDrawerLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/cl_md"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <LinearLayout
                    android:id="@+id/masterToolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    app:layout_constraintBottom_toTopOf="@+id/master_container"
                    app:layout_constraintTop_toTopOf="parent">

                <include layout="@layout/layout_collapsingtoolbar" />
            </LinearLayout>

            <RelativeLayout
                    android:id="@+id/master_container"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/masterToolbar" />
        </androidx.constraintlayout.widget.ConstraintLayout>

        <com.google.android.material.navigation.NavigationView
                android:id="@+id/my_navview"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:fitsSystemWindows="true"
                app:menu="@menu/menu_navdrawer" />

    </androidx.drawerlayout.widget.DrawerLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Расположение CollapsingToolbar

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout
        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="wrap_content"
        android:id="@+id/myAppBarLayout">

    <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/myCollapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|snap|exitUntilCollapsed">

        <androidx.appcompat.widget.Toolbar
                android:id="@+id/myToolbar"
                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>

Текущий результат

enter image description here

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...