Skip to content

Instantly share code, notes, and snippets.

@ShivamKumarJha
Created June 2, 2021 07:04
Show Gist options
  • Save ShivamKumarJha/5517be78503435af95f6e79810d5b2a2 to your computer and use it in GitHub Desktop.
Save ShivamKumarJha/5517be78503435af95f6e79810d5b2a2 to your computer and use it in GitHub Desktop.
recyclerview.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
when (newState) {
RecyclerView.SCROLL_STATE_DRAGGING -> {
Log.d(TAG, "dragging")
}
RecyclerView.SCROLL_STATE_IDLE -> {
Log.d(TAG, "idle")
}
RecyclerView.SCROLL_STATE_SETTLING -> {
Log.d(TAG, "settling")
}
}
if (!recyclerView.canScrollVertically(1) && newState == RecyclerView.SCROLL_STATE_IDLE) {
Log.d(TAG, "bottom")
}
if (!recyclerView.canScrollVertically(-1) && newState == RecyclerView.SCROLL_STATE_IDLE) {
Log.d(TAG, "top")
}
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
when {
dx > 0 -> {
Log.d(TAG, "Scrolled Right")
}
dx < 0 -> {
Log.d(TAG, "Scrolled Left")
}
else -> {
Log.d(TAG, "No Horizontal Scrolled")
}
}
when {
dy > 0 -> {
Log.d(TAG, "Scrolled Downwards")
}
dy < 0 -> {
Log.d(TAG, "Scrolled Upwards")
}
else -> {
Log.d(TAG, "No Vertical Scrolled")
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment