android - 滚动时出现 CollapsingToolbarLayout 和 NestedScrollView 问题

标签 android android-collapsingtoolbarlayout android-nestedscrollview

我有一个简单的 collapsingToolbarLayout xml,如下所示:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/profile_coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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

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

            <ImageView
                    android:id="@+id/img"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:fitsSystemWindows="true"
                    app:layout_collapseMode="parallax" />

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

        </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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="24dp">

            <!--SOME CONTENT-->

        </LinearLayout>

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|right|end"
        android:src="@drawable/ic_mail_white"
        android:layout_margin="@dimen/fab_margin"
        android:clickable="true"/>

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

一切正常,直到我尝试快速从 BOTTOM 滚动到 TOP(从 Nested Scroll View 内容到 CollapsingToolbarLayout)并且嵌套内容覆盖了图像,这太可怕了。我一直在尝试我找到的所有选项,但似乎没有任何效果。

我所有的库都根据文档进行了更新,基本代码来自一些似乎对每个人都适用的基本示例。

谁能帮我解决这个问题?

我提供一些图片来更好地解释问题:

  1. 滚动前内容正常且正确 1. Normal and correct content after scroll

  2. 从嵌套滚动到工具栏时 2. When scrolling from nested to toolbar

最佳答案

我终于明白了这个问题。你的代码是正确的,真正的问题是你的设备。我已经测试了您在我的 LG Nexus 5 上发布的代码,一切正常。这是我的测试应用程序的屏幕截图:

enter image description here

如您所见,滚动效果很好,卡片不会与工具栏重叠。昨天终于有机会在您的手机型号 Huawei P8 Lite 上测试我的代码。这是令人难以置信的结果:

enter image description here

显然,这款华为手机型号(或者其他型号,我不知道)有一个奇怪的错误,在使用 CollapsingToolbarLayout 时会产生重叠问题。

最奇怪的是,我在互联网上到处搜索,但找不到与这个恼人的华为错误相关的任何内容。

要解决这个问题,建议你亲自写信给华为或者..换手机!

关于android - 滚动时出现 CollapsingToolbarLayout 和 NestedScrollView 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40313160/

相关文章:

android - NestedScrollView 内的水平 RecyclerView,无法垂直滚动

android - 拦截RecyclerView在NestedScrollView中向下滑动

javascript - iframe 的安全错误

Android:如何创建类似于日历应用程序的布局 - 创建事件

android - 芝士方 block : enterAlways produces wrong layout

android - 折叠时如何更改折叠工具栏的颜色?

android - NestedScrollView 布局中的 RecyclerView 不滚动

android - Rect改左后笔画的边变大了

android - 在颜色选择器中使用 appcompat 的 ?colorAccent 似乎不起作用

android - 一个 View 内的多个回收 View (gridlayout 和水平线性布局)