RecyclerView 禁用和启用所有事件
Posted 安果移不动
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RecyclerView 禁用和启用所有事件相关的知识,希望对你有一定的参考价值。
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.recyclerview.widget.RecyclerView
class InterceptingRecyclerView(context: Context, attrs: AttributeSet?) : RecyclerView(context, attrs)
var isInterceptingEvents = false
override fun dispatchTouchEvent(ev: MotionEvent): Boolean
return if (isInterceptingEvents)
true // consume the event
else
super.dispatchTouchEvent(ev) // let the event pass through
然后用的时候
fun enableRv(enable: Boolean)
mBinding.rvSentenceList.isInterceptingEvents = !enable
不拦截enable 就给true 否则给false
以上是关于RecyclerView 禁用和启用所有事件的主要内容,如果未能解决你的问题,请参考以下文章