Skip to content

Instantly share code, notes, and snippets.

@Farbklex
Created January 28, 2020 09:36
Show Gist options
  • Save Farbklex/a4a05a7764387ef965749936211d0b1a to your computer and use it in GitHub Desktop.
Save Farbklex/a4a05a7764387ef965749936211d0b1a to your computer and use it in GitHub Desktop.
Simple "flashing" animation for an android view
package me.a_hoffmann.gists
import android.animation.ValueAnimator
import android.view.View
object FlashingAnimator {
const val ANIMATION_DURATION: Long = 800
/**
* Executes a "flashing" animation on a view
*/
fun playHighlightAnimation(view: View) {
val animator = ValueAnimator.ofFloat(0.1f, 1f)
animator.addUpdateListener { valueAnimator ->
view.alpha = valueAnimator.animatedValue as Float
view.requestLayout()
}
animator.duration = ANIMATION_DURATION
animator.start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment