How to Create Similar Collapsing Transparent Tool Bar like Netflix

Viewed 196

How to create a collapsing toolbar like how netflix does it. The recyclerview can draw behind the status bar while the toolbar doesn't.

I tried creating one but somehow can't get it to work. Setting the android:fitsSystemWindows="false" to the coordinator layout also affects the toolbar.

Sample Pic

enter image description here

fragment_main.xml

<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="false"
    android:background="@color/netflix_black">
    <include

        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/content"
        layout="@layout/layout_content"/>
    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/toolBarLayoutView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp"
        android:background="@android:color/transparent"
        >
        <androidx.appcompat.widget.Toolbar

            android:id="@+id/toolbar"
            app:layout_scrollFlags="scroll|enterAlways"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize">

            <ImageView
                android:layout_width="56dp"
                android:layout_height="match_parent"
                android:layout_marginStart="8dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:src ="@drawable/logo_netflix"
                />

        </androidx.appcompat.widget.Toolbar>

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

</androidx.coordinatorlayout.widget.CoordinatorLayout>

layout_content.xml

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/toolBarLayoutView"
    android:layout_width="match_parent"
    android:background="@android:color/transparent"
    android:layout_height="match_parent"
   xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"

    >
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/parentRv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:overScrollMode="never"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"

        />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
0 Answers
Related