【问题标题】:OnClick event does't called after scrolling with CollapsingToolbarLayout.使用 CollapsingToolbarLayout 滚动后不会调用 OnClick 事件。
【发布时间】:2018-06-01 02:04:42
【问题描述】:

我用CollapsingToolbarLayout实现了视差效果,发现一个问题:当我在滚动和视差效果之后立即点击RecyclerView项目时,onClick事件没有被调用,但是onTouch事件987654325@ 被调用。
如果您等待几秒钟(不点击),它会运行良好。

<android.support.design.widget.CoordinatorLayout
    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"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll">

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:fitsSystemWindows="true"
                android:src="@drawable/img_stub"/>

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>

当我将app:layout_scrollFlags="scroll" 添加到 CollapsingToolbarLayout 时出现问题。
我认为它可以取决于稀松布动画......

【问题讨论】:

  • 您好 Dima,我遇到了完全相同的问题,我花了几天时间才将其缩小到这个问题。您找到解决方法了吗?

标签: android android-coordinatorlayout android-collapsingtoolbarlayout android-design-library android-scroll


【解决方案1】:

这似乎是NestedScrollView 中的一个错误。您可以使用来自hereFixedAppBarLayoutBehaviour 来解决此问题。

并将其添加到您的AppBarLayout,如下所示:

 <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_height="..."
        android:layout_width="..."
        app:layout_behavior="your.package.FixAppBarLayoutBehavior">

【讨论】:

  • 今天,我整个晚上都在解决这个问题。当涉及到 NestedScrollView 时,在 UI 开始在按钮上注册 OnClick 事件之间存在延迟(奇怪的是仅在某些手机上)。 @Petr 提供的解决方法对我有用。 Dik za 提示 :)。
【解决方案2】:

我为这个错误创建了一个问题。 https://issuetracker.google.com/issues/70883270

这是支持库开发团队的回答: “我们的工程团队已经解决了这个问题。它将在未来的支持库版本中提供。”

【讨论】:

    猜你喜欢
    • 2016-03-22
    • 2016-07-02
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    • 2017-06-09
    • 2020-06-04
    相关资源
    最近更新 更多