Created
May 5, 2019 20:41
-
-
Save bitvale/f94e9be9b2c105c6697e15ed089afade to your computer and use it in GitHub Desktop.
For Medium article "Animate Everything! (Android Animation Showcase)"
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
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