Skip to content

Instantly share code, notes, and snippets.

@nickbutcher
Last active July 24, 2019 20:58
Show Gist options
  • Save nickbutcher/c1d148d4cbe7605bc447bb68cdc5abd8 to your computer and use it in GitHub Desktop.
Save nickbutcher/c1d148d4cbe7605bc447bb68cdc5abd8 to your computer and use it in GitHub Desktop.
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
fun animateVisibility(view: View, visible: Boolean) {
view.visibility = View.VISIBLE
if (visible) {
ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f).start()
} else {
ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f).apply {
doOnEnd { view.visibility = View.GONE }
}.start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment