RecyclerView behavior_overlapTop 没有父调整大小

RecyclerView behavior_overlapTop without parent resize

我正在使用 CollapsingToolbarLayoutRecyclerView 来显示一些电影细节。我已将 behavior_overlapTop="40dp" 设置为在背景图片上显示电影海报。一切正常,但是当滚动时,灰色背景的一小部分会调整大小以填充 RecyclerViewToolbar 之间的间隙,如图所示:

这是我的布局:

<?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>

有没有办法禁用它?或者至少将颜色更改为白色? 谢谢。

是你开始打开应用栏时出现的那条细黑线吗?那是工具栏的高度。要关闭它,请将以下内容添加到工具栏 XML:

android:elevation="0dp"

您还可以使用 setElevation() 以编程方式操作海拔高度。如果您希望高程阴影出现在某些时候而不是其他时候,这可能很有用。

我没有找到使扩展部分保持透明的解决方案,我找到了一种变通方法,只需使用具有两种颜色的自定义 window 背景即可使其变白:顶部白色和底部灰色。