微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

防止 ItemTouchHelper 在 RecyclerView 中的 Scrollview 中的 TextView 滚动时触发

如何解决防止 ItemTouchHelper 在 RecyclerView 中的 Scrollview 中的 TextView 滚动时触发

我想我有一个简单的问题,但由于我是初学者,我不知道如何解决它。我在 recyclerview 中有一个简单的列表,还有一个附加到列表项的 itemtouchhelper。 recyclerview 在约束布局内的滚动视图中显示一个 Textview。所以一切正常,滚动视图的滚动效果很好,buuut

如果我开始滚动 textview 然后释放我的拇指,同时它的自动滚动(它有一些动力),然后将我的拇指放回视图上,因为我想继续滚动,itemtouchhelper 被触发。这导致行为,即视图正在滚动,同时触发 itemtouchhelper 并等待用户将项目拖到另一个地方。

  <androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/constraint_layout_note"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/scrollView_note"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginEnd="1dp"
        android:layout_marginBottom="1dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/note_string"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

所以我基本上想要的是防止 itemtouchhelper 被触发,只要 textview 正在滚动(即使是它自己),而不是只要用户将他的拇指放在 textview 上。我尝试尝试覆盖视图中的 on Touch 方法和命令 v?.parent?.requestdisallowInterceptTouchEvent(true) 例如像这样

        init {
    
        binding.noteString.setonTouchListener { v,event ->
            v?.parent?.requestdisallowInterceptTouchEvent(false)
            true
        }
        binding.scrollViewNote.setonTouchListener(View.OnTouchListener { v,event ->
            v.parent.requestdisallowInterceptTouchEvent(true)
            false
        })

        binding.constraintLayoutNote.setonTouchListener { v,event ->
            v?.parent?.requestdisallowInterceptTouchEvent(false)
            false
        }

但我所做的只是完全停止滚动。

我自己无法取得任何进展,所以我想请教一下这里的人。有人知道一些帮助吗?如何检测,如果 textview 正在滚动,然后阻止 itemtouchhelper 触发?

提前谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。