Android-滚动时CollapsingToolbarLayout和NestedScrollView的问题

3

我有一个简单的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>

一切都很正常,直到我尝试快速从底部向上滚动(从嵌套滚动视图内容到CollapsingToolbarLayout),嵌套内容超过图像,这太糟糕了。我已经尝试了所有我找到的选项,但似乎没有什么作用。
根据文档,我的所有库都已更新,并且基础代码来自一些基本示例,对于每个人都有效。
有人能帮我解决这个问题吗?
我提供一些图片以更好地解释问题:
1. 滚动前的正常和正确内容 1. Normal and correct content after scroll 2. 从嵌套滚动到工具栏时滚动 2. When scrolling from nested to toolbar

我在我的设备上测试了你的代码,似乎运行正常。也许如果你告诉我你的手机型号,我可以进行一些测试,以更好地了解问题是否与你的手机有关,而不是代码本身。 - Mattia Ruggiero
1
我正在使用一台华为 P8 Lite 手机。 - Damian Dominella
华为荣耀5,我也遇到了同样的问题。即使使用setExtended()方法也无法正常工作。 - lenhuy2106
1个回答

4
我终于理解了问题所在。你的代码是正确的,真正的问题是你的设备。我在我的LG Nexus 5上测试了你发布的代码,一切都很好。这里是我测试应用程序的截图:enter image description here
如您所见,滚动条运行良好,卡片不会重叠到工具栏上。昨天,我终于有机会在你的手机型号华为P8 Lite 上测试我的代码。结果令人难以置信:enter image description here
显然,这款华为手机(或其他型号,我不知道)存在一个奇怪的bug,在使用CollapsingToolbarLayout时会导致重叠问题。
最奇怪的是,我在互联网上搜索了所有相关信息,但是我找不到任何与这个令人讨厌的华为手机bug有关的信息。
要解决这个问题,我建议你亲自写信给华为或者换一部手机!

1
你说得对,我现在已经测试过了,这是一个华为的问题。谢谢! - Damian Dominella

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接