Created
September 17, 2017 23:07
-
-
Save jsaund/6c724114cbc45efaa4281e68ff8436ae to your computer and use it in GitHub Desktop.
SnapHelper tip: limit the maximum fling distance
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
private var scroller: Scroller? = null | |
private val minX = -2000 | |
private val maxX = 2000 | |
private val minY = -2000 | |
private val maxY = 2000 | |
override fun attachToRecyclerView(recyclerView: RecyclerView?) { | |
scroller = Scroller(recyclerView?.context, DecelerateInterpolator()) | |
super.attachToRecyclerView(recyclerView) | |
} | |
override fun calculateScrollDistance(velocityX: Int, velocityY: Int): IntArray { | |
val out = IntArray(2) | |
scroller?.fling(0, 0, velocityX, velocityY, minX, maxX, minY, maxY) | |
out[0] = scroller?.finalX ?: 0 | |
out[1] = scroller?.finalY ?: 0 | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment