Skip to content

Instantly share code, notes, and snippets.

@bitvale
Created May 5, 2019 20:41
Show Gist options
  • Save bitvale/f94e9be9b2c105c6697e15ed089afade to your computer and use it in GitHub Desktop.
Save bitvale/f94e9be9b2c105c6697e15ed089afade to your computer and use it in GitHub Desktop.
For Medium article "Animate Everything! (Android Animation Showcase)"
class AnimatedLayoutManager constructor(private val context: Context) : LinearLayoutManager(context) {
// other code
override fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): Int {
if (childCount == 0) return 0
val legal = super.scrollVerticallyBy(dy, recycler, state)
calculateDy(dy)
updateViews()
return legal
}
private fun updateViews() {
for (i in 0 until childCount) {
val view = getChildAt(i)
view.let {
val value = ((paddingTop - it.top) / it.height.toFloat())
it.alpha = 1f - value
var scale = 1f - value / 20f
if (scale > 1) scale = 1f
it.scaleX = scale
it.scaleY = scale
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment