【问题标题】:Touch intercepted after fling投掷后触摸被截获
【发布时间】:2015-10-29 12:56:55
【问题描述】:

最近我的滚动视图遇到了一些问题。触发事件后,触摸事件不会到达滚动视图内的元素。发生投掷后,我首先需要再次点击视图,然后恢复正常行为。我已经尝试了很多解决方法,例如:

  • 在投掷后手动触发运动事件(向上/向下)。这可行,但有一些严重的问题,我不必解释为什么我猜,因为这与再次触摸视图相同,但在某个 x+y 处。
  • 拦截触摸事件并始终将它们传递给底层视图。

但这一切都很麻烦,而且这似乎首先是不受欢迎的行为,不是吗?

似乎滚动视图会在 onfling 发生后拦截所有内容,直到新的正常(无 fling)向上和向下触摸。

 <android.support.v4.widget.NestedScrollView
    android:id="@+id/fsv_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/white">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/marker"
        android:padding="@dimen/spacing_small"/>

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

</LinearLayout>

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

【问题讨论】:

    标签: android touch-event nestedscrollview


    【解决方案1】:

    您有一个滚动视图 (NestedScrollView),其中包含另一个滚动视图 (RecyclerView)。 对我来说听起来很麻烦。

    为什么需要这样的布局?

    【讨论】:

    • 是的,但我很确定这不是问题所在。 NestedScrollView 和 RecyclerView 可以一起工作。您可以在 RecyclerView 中使用自定义布局行为。当您想要滚动所有内容时使用此选项,您的布局中的 imageView 或其他内容以及 RecyclerView 中的内容也是如此。如果我在这方面错了,请纠正我?
    • 支持滚动的视图(ScrollView/RecyclerView)可以在检测到某个看起来像滚动的触摸事件时劫持其子级的触摸事件,我认为当这两个视图争夺控制权时可能会导致问题的滚动动作。
    • 如果您真的不需要 RecyclerView 来滚动,请尝试使用像 LinearLayout 这样的非滚动视图。
    • 嗯,是的,但我仍然想要 RecyclerView 的好处。就像工具栏第一次使用新的 coordinatorlayout 向上滑动一样,之后内容(RecyclerView)需要向上滑动。与向下滑动相同,首先 RecyclerView 需要向下滑动所有结果,直到没有比顶部的静态内容需要滑入的剩余(第一个结果)。
    • 我不认为这是这样做的方法,在stackoverflow中搜索RecyclerView标头,有一些解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    相关资源
    最近更新 更多