Skip to content

Instantly share code, notes, and snippets.

@andrefrsousa
Created October 28, 2018 14:33
Show Gist options
  • Save andrefrsousa/6c47b56bee063e633df2663784d4d198 to your computer and use it in GitHub Desktop.
Save andrefrsousa/6c47b56bee063e633df2663784d4d198 to your computer and use it in GitHub Desktop.
Show toolbar elevation using a RecyclerView
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
toolbar.setElevationVisibility()
if (recyclerView.canScrollVertically(-1)) {
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