Created
October 17, 2019 21:53
-
-
Save andrewsafwatsamuel/204aa5979ca7666c42db70eb518fb35e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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