RecyclerView的touch事件

本文详细探讨了RecyclerView在处理触摸事件时的行为,包括onTouchEvent和onInterceptTouchEvent的交互,特别是dispatchOnItemTouch方法中如何通过监听器拦截事件。在ACTION_DOWN、ACTION_MOVE和ACTION_UP阶段,分析了RecyclerView如何判断是否可以滑动、处理滑动距离以及调用fling方法。同时,提到了布局管理器的角色,以及ItemDecorations在滑动时的重绘效果。
摘要由CSDN通过智能技术生成

RecyclerView的onInterceptTouchEvent(MotionEvent e)和onTouchEvent方法比较类似,这里就只分析onTouchEvent

首先看到 dispatchOnItemTouch(MotionEvent e) 方法

private boolean dispatchOnItemTouch(MotionEvent e) {
        final int action = e.getAction();
        if (mActiveOnItemTouchListener != null) {
            if (action == MotionEvent.ACTION_DOWN) {
                // Stale state from a previous gesture, we're starting a new one. Clear it.
                mActiveOnItemTouchListener = null;
            } else {
                mActiveOnItemTouchListener.onTouchEvent(this, e);
                if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
                    // Clean up for the next gesture.
                    mActiveOnItemTouchListener = null;
                }
                return true;
            }
        }
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值