Skip to content

Instantly share code, notes, and snippets.

@andrefrsousa
Last active October 28, 2018 14:34
Show Gist options
  • Save andrefrsousa/3fbc42333bb99328feff04957ad60077 to your computer and use it in GitHub Desktop.
Save andrefrsousa/3fbc42333bb99328feff04957ad60077 to your computer and use it in GitHub Desktop.
Show toolbar elevation using a NestedScrollView
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