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
}
相关推荐
gjxDaniel1 天前
Kotlin编程语言入门与常见问题
android·开发语言·kotlin
野生技术架构师1 天前
Java 21虚拟线程 vs Kotlin协程:高并发编程模型的终极对决与选型思考
java·开发语言·kotlin
言之。1 天前
Kotlin快速入门
android·开发语言·kotlin
常利兵1 天前
Android Gradle 构建脚本现代化:Kotlin DSL (.kts) 与 Groovy DSL 深度对比与实战指南
android·开发语言·kotlin
baidu_247438611 天前
Android kotlin 定时n秒完成时回调,含暂停和继续
android·kotlin
stevenzqzq1 天前
kotlin和compose中使用by
kotlin·compose
符哥20081 天前
Android 开发中如何使用Coroutines
android·kotlin
sinat_267611912 天前
跟着官网学习协程随笔
学习·kotlin
缺一句感谢和缺一句道歉2 天前
Module was compiled with an incompatible version of Kotlin.
java·kotlin
灯火不休ᝰ2 天前
[安卓] Kotlin中的架构演进:从MVC到MVVM
android·架构·kotlin