我想创建带有滚动内容的 CardStackView,但在使用 NestedScrollView 和 onTouchListener 时遇到一些问题。
我正在使用 CardStackView,我想在 CardView 中添加滚动内容。在行 XML 文件中添加 NestedScrollView 后,我的 Swipe 无法正常工作。
holder.textViewCheck.setOnTouchListener(onTouchListener())
在下面的代码中,我在 TouchListener 中检测左右滑动时禁用滚动,但一次只有一个功能在工作。
private var xDelta: Int = 0
private var yDelta: Int = 0
private fun onTouchListener(): OnTouchListener {
return OnTouchListener { view, event ->
val x = event.x.toInt()
val y = event.y.toInt()
val tAG = "AppName"
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
cardStackManager.setSwipeableMethod(SwipeableMethod.None)
xDelta = x
yDelta = y
true
}
MotionEvent.ACTION_UP -> {
cardStackManager.setSwipeableMethod(SwipeableMethod.AutomaticAndManual)
Toast.makeText(mContext, "thanks for new location!", Toast.LENGTH_SHORT).show()
false
}
MotionEvent.ACTION_MOVE -> {
val finalX = event.x
val finalY = event.y
// Log.e(tAG, "xDelta $xDelta ---------- FinalX $finalX ---------- Final+X ${xDelta + 100}")
// Log.e(tAG, "xDelta $xDelta ---------- FinalX $finalX ---------- Final-X ${xDelta - 100}")
when {
finalX > xDelta + 100 -> {
view.parent.requestDisallowInterceptTouchEvent(false)
cardStackManager.setSwipeableMethod(SwipeableMethod.AutomaticAndManual)
// Log.e(tAG, "Left to Right swipe performed")
true
}
finalX < xDelta - 100 -> {
view.parent.requestDisallowInterceptTouchEvent(false)
cardStackManager.setSwipeableMethod(SwipeableMethod.AutomaticAndManual)
// Log.e(tAG, "Right to Left swipe performed")
true
}
yDelta < finalY -> {
view.parent.requestDisallowInterceptTouchEvent(true)
cardStackManager.setSwipeableMethod(SwipeableMethod.None)
// Log.e(tAG, "Up to Down swipe performed")
false
}
yDelta > finalY -> {
view.parent.requestDisallowInterceptTouchEvent(true)
cardStackManager.setSwipeableMethod(SwipeableMethod.None)
// Log.e(tAG, "Down to Up swipe performed")
false
}
}
}
}
true
}
}
以下链接是 CardStakeView 库的链接,用于轻松检查和理解我的问题。
我正在自定义这个库
https://github.com/yuyakaido/CardStackView
谢谢
最佳答案
我想你想实现独立的滚动 Action 对吧? https://github.com/TakuCoder/MultiScrollView.git关注我的 github 存储库
关于android - 如何管理 onTouchListener 从 ACTION_MOVE 事件返回值,就像我想在调用 ACTION_MOVE 事件时更改(true 或 false)返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58391492/