嗨,我使用DiscreteScrollView作为水平可滚动列表,我对recyclerView项实现了onTouchListener来检测swipeUp并单击以打开卡,但是当我尝试以天使滑动时似乎出现了问题(见图)。
它滚动而不是向上滑动来打开卡。
override fun onfling(
e1: MotionEvent,e2: MotionEvent,velocityX: Float,velocityY: Float
): Boolean {
val result = false
try {
val diffY = e2.y - e1.y
val diffX = e2.x - e1.x
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
onSwipeRight()
Log.d("swipe","swipe right")
} else {
onSwipeleft()
Log.d("swipe","swipe left")
}
}
} else {
if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (diffY > 0) {
onSwipeBottom()
Log.d("swipe","swipe bottom")
} else {
onSwipeTop()
Log.d("swipe","swipe top")
}
}
}
} catch (exception: Exception) {
exception.printStackTrace()
}
return result
}
我的OnSwipeTouchListener可以识别卡上的滑动
这是图书馆的ScrollLayoutManager
关于如何处理此问题的任何想法,我都可以将其识别为swipeUp,而不是开始滚动recyclerview。
谢谢。
编辑:
我正在使用GestureDetector.SimpleonGestureListener(),并且未触发onfling方法,因此我查看是否正在调用任何其他方法,并看到正在调用onScroll方法。我刚刚实现了SimpleonGestureListener的onScroll方法,并添加了相同的代码来识别滑动,现在它可以工作了。