Skip to content

Instantly share code, notes, and snippets.

@andrewsafwatsamuel
Created October 17, 2019 21:53
Show Gist options
  • Save andrewsafwatsamuel/204aa5979ca7666c42db70eb518fb35e to your computer and use it in GitHub Desktop.
Save andrewsafwatsamuel/204aa5979ca7666c42db70eb518fb35e to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
val fadeAnimator by lazy {
ObjectAnimator.ofFloat(targetImage,"alpha",1.0f,0.0f)
.apply {duration=1500}
.apply { repeatCount=1 }
.apply { repeatMode=ObjectAnimator.REVERSE }
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
handleButtonClicks()
}
private fun handleButtonClicks() {
rotate_button.setOnClickListener { startAnimation(R.animator.rotate, targetImage) }
fade_button.setOnClickListener { /*startAnimation(R.animator.alpha, targetImage) */
fadeAnimator.start()}
translate_button.setOnClickListener { startAnimation(R.animator.translate, targetImage) }
scale_button.setOnClickListener { startAnimation(R.animator.scale, targetImage) }
}
fun Context.startAnimation(srcId: Int, target: Any) = AnimatorInflater.loadAnimator(this, srcId)
.apply { setTarget(target) }
.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment