Last active
October 28, 2018 14:34
-
-
Save andrefrsousa/3fbc42333bb99328feff04957ad60077 to your computer and use it in GitHub Desktop.
Show toolbar elevation using a NestedScrollView
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
scrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, _ -> | |
if (toolbar == null) { | |
return@OnScrollChangeListener | |
} | |
if (scrollY > 0) { | |
ViewCompat.animate(this).translationZ(toolbarElevation).run { | |
interpolator = DecelerateInterpolator() | |
duration = animationDuration | |
start() | |
} | |
} else { | |
ViewCompat.animate(this).translationZ(0f).run { | |
interpolator = DecelerateInterpolator() | |
duration = animationDuration | |
start() | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment