Created
May 1, 2020 17:24
-
-
Save goforbg/84e6e475c68ac56915af7288268ecae7 to your computer and use it in GitHub Desktop.
Handling scrolls between horizontal Recylerview and horizontal swipeable Viewpager2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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