In my vertical recyclerview, I have multiple horizontal recyclerviews and I have a problem: when I want to scroll left or right, if I'm scrolling a bit up or down at the same time, the horizontal scrolling doesn't work.
So my idea was to redefine what is up, down, left and right for the recycler view. So I stumbled upon this thread : How to detect swipe direction between left/right and up/down
First I though it was what I need but then I understood, it was just redefining directions at the end of a swipe (not during), so I tried to do all the angle computation during the swipe. I ended with this :
var initialX: Float
var initialY: Float
ui_recyclerView?.setOnTouchListener(object: View.OnTouchListener{
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
val action = event?.actionMasked
if (action == MotionEvent.ACTION_DOWN) {
initialX = event.x
initialY = event.y
}
else if(action == MotionEvent.ACTION_MOVE) {
val swipeDirection = GestureUtils.getSwipeDirection(initialX, initialY, event.x, event.y)
if (swipeDirection == GestureUtils.Direction.UP || swipeDirection == GestureUtils.Direction.DOWN) {
return false
}
}
return true
}
})
It worked but then I didn't have the smooth scrolling any more (it was very robotic), and neither the click.
Is there a built-in function with recycler view to limit MoveEvent to a certain angle ? If not, how can I put back the smooth scrolling effect of a normal recycler view ?
That would help me a lot !