SmartRefreshLayout+ CoordinatorLayout+ AppBarLayout滑动事件冲突

添加了上述的 事件冲突检测代码进行调试:

coordinatorLayout.setOnTouchListener { v, event ->
    Log.d("EVENT", "CoordinatorLayout touch: ${event.action}")
    false // 不拦截
}

当滑动页面中的AppBarLayout这块区域 页面可以正常滑动时的log输出如下:
2025-06-19 00:23:32.806 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 0
2025-06-19 00:23:32.823 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 2
2025-06-19 00:23:32.862 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 2
2025-06-19 00:23:32.891 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 2
2025-06-19 00:23:33.119 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 2
2025-06-19 00:23:33.120 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 1
根据输出可以看到有down、move、up事件

但是当滑动页面中的AppBarLayout这块区域 页面无法正常滑动时的log输出如下:
2025-06-19 00:27:10.429 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 0
2025-06-19 00:27:11.285 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 0
2025-06-19 00:27:13.654 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 0
2025-06-19 00:27:14.052 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 0
2025-06-19 00:27:14.804 10373-10373 EVENT com.superex.ex D CoordinatorLayout touch: 0

根据输出可以看到只有down事件,问题出在哪里?如何解决

继续调试

添加了上述的调试代码:

// 在 CoordinatorLayout 的父布局添加监听
smartRefreshLayout.setOnTouchListener { v, event ->
    Log.d("EVENT", "SmartRefreshLayout touch: ${event.action}")
    false
}

// 在 AppBarLayout 添加监听
appBarLayout.setOnTouchListener { v, event ->
    Log.d("EVENT", "AppBarLayout touch: ${event.action}")
    false
}

然后继续调试

当滑动页面中的AppBarLayout这块区域 页面可以正常滑动时的log输出如下:

2025-06-19 00:47:30.117 10853-10853 EVENT com.superex.ex D CoordinatorLayout touch: 0
2025-06-19 00:47:30.146 10853-10853 EVENT com.superex.ex D CoordinatorLayout touch: 2
2025-06-19 00:47:30.347 10853-10853 EVENT com.superex.ex D CoordinatorLayout touch: 2
2025-06-19 00:47:30.347 10853-10853 EVENT com.superex.ex D CoordinatorLayout touch: 1

发现当滑动页面中的AppBarLayout这块区域 页面无法正常滑动时的log输出如下:

2025-06-19 00:45:14.219 10853-10853 EVENT com.superex.ex D CoordinatorLayout touch: 0
2025-06-19 00:45:14.219 10853-10853 EVENT com.superex.ex D SmartRefreshLayout touch: 0
2025-06-19 00:45:14.276 10853-10853 EVENT com.superex.ex D SmartRefreshLayout touch: 2
2025-06-19 00:45:14.332 10853-10853 EVENT com.superex.ex D SmartRefreshLayout touch: 2
2025-06-19 00:45:14.332 10853-10853 EVENT com.superex.ex D SmartRefreshLayout touch: 1

可以看到,SmartRefreshLayout 消耗了move和up事件,导致CoordinatorLayout没有接收到move、up事件,因此滑动效果失效,如何解决

你可能感兴趣的:(android)