CollapsingToolbarLayout / Toolbar过早/晚退色

时间:2017-04-19 12:51:35

标签: android

我的CollapsingToolbarLayout工作不够准确。图1显示了初始状态,图像2显示了那个,当我向下滚动一点时。过渡发生得太早,最终会出现(在这种情况下)粉红色的空白区域。再次向上滚动时会发生同样的情况。 有什么方法可以解决这个问题吗?

我的布局:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/activity_main_cover_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

      <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:background="@color/transparent_background_dark"
                android:orientation="vertical"
                android:paddingLeft="@dimen/box_headline_padding"
                android:paddingStart="@dimen/box_headline_padding">

                <!-- ... -->

            </LinearLayout>

        </RelativeLayout>

        <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.Light" />

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

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <!-- ... -->
</android.support.v4.widget.NestedScrollView>

enter image description here enter image description here

2 个答案:

答案 0 :(得分:3)

感谢when the morning,我找到了正确的参数app:scrimVisibleHeightTrigger 最后我结合了两个

app:scrimAnimationDuration="300"
app:scrimVisibleHeightTrigger="60dp"

答案 1 :(得分:1)

在CollapsingToolbarLayout中使用此属性:

        app:scrimAnimationDuration="600"

时间以毫秒为单位。

相关问题