【问题标题】:android - CollapsingToolbarLayout and NestedScrollView issue when scrollingandroid - 滚动时的 CollapsingToolbarLayout 和 NestedScrollView 问题
【发布时间】:2017-03-11 19:45:24
【问题描述】:

我有一个简单的 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(从嵌套滚动视图内容到 CollapsingToolbarLayout)并且嵌套内容覆盖图像,这太可怕了。我一直在尝试所有我发现的选项,但似乎没有任何效果。

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

谁能帮我解决这个问题?

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

  1. 滚动前正常且正确的内容

  2. 从嵌套滚动到工具栏时

【问题讨论】:

  • 我在我的设备中测试了你的代码,它似乎工作正常。也许如果你告诉我你的手机型号,我可以做一些测试,以更好地了解问题是否与你的手机有关,而不是你的代码。
  • 我使用的是华为 P8 Lite
  • 荣誉5在这里,遇到了同样的问题。甚至 setExtended() 也不能正常工作。

标签: android android-collapsingtoolbarlayout android-nestedscrollview


【解决方案1】:

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

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

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

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

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

【讨论】:

  • 你是对的..,我已经测试过了,这是华为的问题。谢谢!
猜你喜欢
  • 1970-01-01
  • 2015-08-28
  • 1970-01-01
  • 2019-07-08
  • 1970-01-01
  • 1970-01-01
  • 2018-02-11
  • 2016-07-31
  • 2016-05-31
相关资源
最近更新 更多