SwipeRefreshLayout和TextView滑动冲突的暴力解决方法

SwipeRefreshLayout和TextView滑动冲突

如果SwipeRefreshLayout中存在TextView,并且TextView被设置为可以上下滑动,那么在下滑TextView的时候会与SwipeRefreshLayout冲突,系统优先判断为SwipeRefreshLayout
网上查到的解决方案是,给TextView设置onTouchListener,在MotionEvent.ACTION_MOVE的时候禁止其parent获取滑动状态,实际用下来发现时灵时不灵的,思来想去想出了一个最简单暴力的解决方法:在点击TextView的时候禁用下拉刷新功能

kotlin 复制代码
mSwipe = findViewById(R.id.swipeRefresh)
tvText.setOnTouchListener { _, event ->
       when (event.action) {
           MotionEvent.ACTION_DOWN -> mSwipe.isEnabled = false
           MotionEvent.ACTION_UP -> mSwipe.isEnabled = true
       }
       return@setOnTouchListener false
}
相关推荐
Kapaseker2 小时前
凌晨两点磨锋芒 调试采坑莫慌张
android·kotlin
F_D_Z17 小时前
岭回归(Ridge Regression)辨析
回归·kotlin·l2正则
6666v621 小时前
Android Kotlin(3) Flow异步流
android·kotlin
QING6181 天前
Kotlin Flow 中 flatMap 与 flatMapLatest 的核心差异 —— 新手指南
android·kotlin·android jetpack
HeDongDong-1 天前
Kotlin Lambda 表达式详解
android·开发语言·kotlin
aqi002 天前
FFmpeg开发笔记(九十六)采用Kotlin+Compose的视频编辑器OpenVideoEditor
android·ffmpeg·kotlin·音视频·流媒体
Lei活在当下3 天前
【日常知识积累】Kotlin let 函数、inline 函数以及 DSL
android·kotlin·编程语言
橙子199110163 天前
Scaffold
android·kotlin·android jetpack
程序员老刘4 天前
Kotlin vs Dart:当“优雅”变成心智负担,我选择了更简单的 Dart
flutter·kotlin·dart
QING6184 天前
Kotlin协程:Job.cancel() 和 Scope.cancel() 的区别详解!!!
android·kotlin·android jetpack