Search code examples
androidandroid-recyclerviewoverlapandroid-collapsingtoolbarlayout

RecyclerView behavior_overlapTop without parent resize


I'm using a CollapsingToolbarLayout with a RecyclerView to show some movie details. I've set behavior_overlapTop="40dp" to show the movie's poster over the background image. Everything works good but when scrolling there is a small part of the gray background that get resized to fill the gap between RecyclerView and Toolbar, as you can see in the image:

enter image description here

This is my layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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="true"
    tools:ignore="ContentDescription">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="220dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:layout_behavior="com.est.streamcorn.ui.customs.FixAppBarLayoutBehavior">

        <com.est.streamcorn.ui.customs.widgets.CustomCollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            app:scrimAnimationDuration="250"
            app:titleEnabled="false">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax">

                <ImageView
                    android:id="@+id/trailer_image"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:scaleType="centerCrop" />

                <android.support.v7.widget.AppCompatButton
                    android:id="@+id/trailer_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:background="@drawable/trailer_button_background"
                    android:drawablePadding="10.0dip"
                    android:drawableStart="@drawable/ic_play"
                    android:minHeight="40.0dip"
                    android:paddingEnd="25.0dip"
                    android:paddingStart="20.0dip"
                    android:text="@string/trailer"
                    android:textAllCaps="false"
                    android:textColor="@color/white"
                    android:textSize="15.0sp"
                    android:visibility="invisible"
                    tools:visibility="visible"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

            </android.support.constraint.ConstraintLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat">

                <TextView
                    android:id="@+id/toolbar_title"
                    style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:ellipsize="end"
                    android:singleLine="true" />

            </android.support.v7.widget.Toolbar>

        </com.est.streamcorn.ui.customs.widgets.CustomCollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:behavior_overlapTop="40dp"
        android:paddingBottom="5dp"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

Is there a way to disable this? Or at least to change the color to white? Thank you.


Solution

  • I didn't find a solution to keep the expanding part transparent, by I found a workaround to make it white by simply using a custom window's background with two colors: the top part white and the bottom part grey.