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
}
相关推荐
黄林晴28 分钟前
用了这么久 Koin Scope,原来一直都用错了?
android·kotlin
唐青枫1 天前
Kotlin Context Parameters 详解:别再把 Logger、事务和配置层层往下传
kotlin
Coffeeee1 天前
如何使用Glide和Coil加载WebP动图
android·kotlin·glide
Kapaseker1 天前
5 分钟搞懂 Kotlin DSL
android·kotlin
alexhilton2 天前
使用Android Archive进行打包
android·kotlin·android jetpack
逐光老顽童4 天前
Java 与 Kotlin 混合开发避坑指南:30 个真实案例实录
android·kotlin
plainGeekDev5 天前
null 判断 → Kotlin 可空类型
android·java·kotlin
plainGeekDev5 天前
getter/setter → Kotlin 属性
android·java·kotlin
Junerver5 天前
我写了一个 Compose Multiplatform 组件库,你可能会用到
kotlin·android jetpack
Ehtan_Zheng6 天前
Kotlin const val vs val:字节码、性能与隐藏陷阱详解
android·kotlin