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