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 禁用和启用所有事件的主要内容,如果未能解决你的问题,请参考以下文章

WPF:禁用ListBox,但启用滚动

禁用 RecyclerView 的所有子视图

应用程序关闭时的 iOS 定位服务启用/禁用事件

如何禁用 ViewPager2 中的滑动?

a 标签 启用或禁用点击事件

如何启用/禁用基于事件的 QTreeView 中的项目?