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
}
相关推荐
alexhilton3 天前
端侧RAG实战指南
android·kotlin·android jetpack
Kapaseker3 天前
2026年,我们还该不该学编程?
android·kotlin
Kapaseker4 天前
一杯美式搞懂 Any、Unit、Nothing
android·kotlin
Kapaseker5 天前
一杯美式搞定 Kotlin 空安全
android·kotlin
FunnySaltyFish6 天前
什么?Compose 把 GapBuffer 换成了 LinkBuffer?
算法·kotlin·android jetpack
Kapaseker6 天前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
Kapaseker7 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
A0微声z9 天前
Kotlin Multiplatform (KMP) 中使用 Protobuf
kotlin
alexhilton10 天前
使用FunctionGemma进行设备端函数调用
android·kotlin·android jetpack
lhDream10 天前
Kotlin 开发者必看!JetBrains 开源 LLM 框架 Koog 快速上手指南(含示例)
kotlin