Skip to content

Instantly share code, notes, and snippets.

@goforbg
Created May 1, 2020 17:24
Show Gist options
  • Save goforbg/84e6e475c68ac56915af7288268ecae7 to your computer and use it in GitHub Desktop.
Save goforbg/84e6e475c68ac56915af7288268ecae7 to your computer and use it in GitHub Desktop.
Handling scrolls between horizontal Recylerview and horizontal swipeable Viewpager2
val listener = object : OnItemTouchListener {
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
val action = e.action
if (recyclerview.canScrollHorizontally(RecyclerView.FOCUS_FORWARD)) {
when (action) {
MotionEvent.ACTION_MOVE -> rv.parent
.requestDisallowInterceptTouchEvent(true)
}
return false
}
else {
when (action) {
MotionEvent.ACTION_MOVE -> rv.parent
.requestDisallowInterceptTouchEvent(false)
}
recyclerview.removeOnItemTouchListener(this)
return true
}
}
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {}
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {}
}
recyclerview.addOnItemTouchListener(listener)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment