Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RecyclerView仅在特定视图触摸时滚动_Android_Kotlin_Android Recyclerview_Scroll - Fatal编程技术网

Android RecyclerView仅在特定视图触摸时滚动

Android RecyclerView仅在特定视图触摸时滚动,android,kotlin,android-recyclerview,scroll,Android,Kotlin,Android Recyclerview,Scroll,我想知道如何实现RecyclerView的这种行为,只有在ViewHolder中单击并拖动特定视图时才能滚动列表 我通过创建自己的LinearLayoutManager禁用了水平滚动: class MyOwnLayoutManager : LinearLayoutManager { constructor(context: Context?) : super(context) constructor(context: Context?, orientation: Int, reverseLay

我想知道如何实现
RecyclerView
的这种行为,只有在
ViewHolder
中单击并拖动特定视图时才能滚动列表

我通过创建自己的LinearLayoutManager禁用了水平滚动:

class MyOwnLayoutManager : LinearLayoutManager {

constructor(context: Context?) : super(context)
constructor(context: Context?, orientation: Int, reverseLayout: Boolean) : super(context, orientation, reverseLayout)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)

private var isScrollEnabled = false

fun setScrollEnabled(isEnabled: Boolean) {
    isScrollEnabled = isEnabled
}

override fun canScrollVertically(): Boolean {
    return isScrollEnabled && super.canScrollVertically()
}

override fun canScrollHorizontally(): Boolean {
    return isScrollEnabled && super.canScrollHorizontally()
}
}
然后,我尝试通过将触摸监听器设置为项目的标题来更改
IsCrollenabled

 item_header.setOnTouchListener { v, event ->
            val isScrolling = event.action == ACTION_MOVE
            onHeaderIsDragging.invoke(isScrolling)
            false
        }
更改适配器布局管理器变量的片段中的回调:

private val onHeaderIsDragging: ((Boolean) -> Unit) = {
    recyclerViewLayoutManager.setScrollEnabled(it)
}
通过此实现,我在
onTouchListener
中的两个
MOTION\u MOVE
事件后获得
MOTION\u CANCEL
,并且
RecyclerView
MOTION\u MOVE
事件后不可滚动