Created
June 2, 2021 07:04
-
-
Save ShivamKumarJha/5517be78503435af95f6e79810d5b2a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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