recyclerview嵌套recyclerview滑动冲突_记一次诡异的滑动冲突bug

作者:barryjiang(江桓桓)

背景

在我还维护着直播播放模块的时光,在某个阳光明媚忧伤的午后,突然收到一个诡异的bug提醒,简单明了的写着 横屏下弹幕区域无法滑动,竖屏下正常 这里整个示意图方便理解:

3aad00b5c1e85315061c26c35406634a.png

dd923c9c1f0d75e84c996abbb3c3e61f.png

思考过程

复盘这个查bug的过程,大致可分为定位问题范围定位debug方向关键节点断点调试根据异常信息假设根据正确的假设找根因

定位问题范围

首先,上来先查看提交日志以及历史构建版本验证,看看是哪个小坏蛋提交的bug呢?一看傻眼,是新版本播放器进行重构时引入的bug,视图层级有了不小的变动:

1.重构前

62583300d858cd070a1e170da49c2eef.png

2.重构后

af113ae07e00122b3c9ac5196f56b8e0.png

ps:这里为了简化问题背景聚焦bug本身,不过多详细描述需求背景,其变更以及实现方式选型,可以后续讨论。这里的VerticalViewpager名如其意,就是竖直方向的Viewpager。

虽然可以获知是Viewpager+RecyclerView的滑动冲突问题,但目前就只能止步于此,无法更进一步获知具体是哪行代码哪个文件改动产生的bug了。

定位debug方向

ok,目前我们知道了Viewpager+RecyclerView的滑动冲突问题,那么..... 并没有什么卵用妈蛋这个不查日志就知道了好么┴┴︵╰(‵□′)╯︵┴┴

冷静冷静,方向很关键,一时找不到方向时,先补充下基础知识开拓思路是很有效的。

Viewgroup事件分发机制(简略版)

先简单过一遍基础的事件分发机制用到的方法,欲了解详情这里有个博文还不错,可以配合官方文档服用,Android事件分发机制详解[1]

一般而言,我们接触的最多是这三个函数:

boolean dispatchTouchEvent (MotionEvent event) Pass the touch screen motion event down to the target view, or this view if it is the target.

Parameters event MotionEvent: The motion event to be dispatched. Returns boolean True if the event was handled by the view, false otherwise.

boolean onInterceptTouchEvent (MotionEvent ev) Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.

Parameters ev MotionEvent: The motion event being dispatched down the hierarchy. Returns boolean Return true to steal motion events from the children and have them dispatched to this ViewGroup through onTouchEvent(). The current target will receive an ACTION_CANCEL event, and no further messages will be delivered here.

boolean onTouchEvent (MotionEvent event) Implement this method to handle touch screen motion events.

If this method is used to detect click actions, it is recommended that the actions be performed by implementing and calling performClick(). This will ensure consistent system behavior, including:

Parameters event MotionEvent

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值