19

我正在尝试使用 CoordinatorLayout 实现 Google 的最新设计技巧,但在滚动和视差效果方面存在问题。

显示 Activity 后,一切看起来都正常,但是当我尝试滚动时出现问题。似乎底部视图未正确展开,向上滚动后,下方出现空白区域。底部视图似乎只有在顶部视图和导航栏之间的初始显示上有多少。

它看起来像这样:

在此处输入图像描述

相关代码:

<FrameLayout 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="match_parent">

<CoordinatorLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent">

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

        <CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:expandedTitleMarginStart="72dp"
            app:expandedTitleMarginEnd="16dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"/>
        </CollapsingToolbarLayout>
    </AppBarLayout>

    <ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</CoordinatorLayout>
</FrameLayout>

这种奇怪的行为是随机发生的。有时底部视图可以正常滚动并且不会出现空白区域。我究竟做错了什么?谢谢。

4

3 回答 3

15

我有同样的问题,我注意到每个有这个问题的布局都有

android:fitsSystemWindows="true"

在 CoordinatorLayout 上

删除它解决了我的问题。

于 2016-01-15T09:38:45.823 回答
1

尝试Toolbar在您的内部添加CollapsingToolbarLayout

 <android.support.design.widget.CollapsingToolbarLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"/>
...
</android.support.design.widget.CollapsingToolbarLayout>

也尝试添加

android:minHeight="?attr/actionBarSize"

Toolbar CollapsingToolbarLayoutAppBarLayout

于 2015-09-22T22:24:41.973 回答
0

由于导航标志的原因 android:fitsSystemWindows="true" 不符合我的需求。

在玩了一些之后,我发现添加另一个带有 0dp hieght 的 CollapsingToolbarLayout 可以解决问题。

<android.support.design.widget.CollapsingToolbarLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_scrollFlags="scroll|snap" />
于 2017-01-05T11:53:21.800 回答