This repo contains all the downloadable materials and projects associated with the Android Animations from raywenderlich.com.
Each edition has its own branch, named versions/[VERSION]
. The default branch for this repo is for the most recent edition.
Branch | Version | Release Date |
---|---|---|
versions/2.0 | 2.0 | 2020-12-08 |
versions/1.0 | 1.0 | 2018-03-26 |
private fun setupUi() {
binding.loginButton.setOnClickListener {
loginViewModel.logIn()
animateLogin()
}
}
private fun animateLogin() {
binding.progressBar.alpha = 0f
binding.progressBar.visibility = View.VISIBLE
val alphaAnimator = ValueAnimator.ofFloat(0f,1f)
alphaAnimator.duration = 1000
alphaAnimator.addUpdateListener {
val animationAlpha = it.animatedValue as Float
binding.progressBar.alpha = animationAlpha
binding.loginButton.alpha = 1 - animationAlpha
}
private fun animateLogin() {
binding.progressBar.alpha = 0f
binding.progressBar.visibility = View.VISIBLE
var buttonWight = binding.loginButton.width
var buttonHeight = binding.loginButton.height
val alphaAnimator = ValueAnimator.ofFloat(0f,1f)
alphaAnimator.duration = 1000
alphaAnimator.addUpdateListener {
val animatedValue = it.animatedValue as Float
binding.progressBar.alpha = animatedValue
binding.loginButton.alpha = 1 - animatedValue * 1.5f
binding.loginButton.updateLayoutParams {
this.height = (buttonHeight * (1f - animatedValue)).toInt()
this.width = (buttonWight * (1f - animatedValue)).toInt()
}
}
alphaAnimator.start()
}
DecelerateInterpolator | AccelerateInterpolator | BounceInterpolator |
alphaAnimator.interpolator = DecelerateInterpolator()
alphaAnimator.interpolator = AccelerateInterpolator()
alphaAnimator.interpolator = BounceInterpolator()
val progressBarAlphaAnimator = ObjectAnimator.ofFloat(binding.progressBar,"alpha", 0f, 1f)
progressBarAlphaAnimator.duration = 3000
progressBarAlphaAnimator.interpolator = BounceInterpolator()
progressBarAlphaAnimator.start()
@RequiresApi(Build.VERSION_CODES.N)
fun transformToProgress() {
val drawable = binding.actionButton.background as? GradientDrawable
val targetWidth = targetButtonWidth
val targetCornerRadius = targetButtonWidth
val cornerAnimator = ValueAnimator.ofFloat(drawable?.cornerRadius ?: 0f, targetCornerRadius.toFloat())
val widthAnimator = ValueAnimator.ofInt(binding.actionButton.measuredWidth, targetWidth)
val progressBarAlphaAnimator = ObjectAnimator.ofFloat(binding.progressBar, "alpha",0f,1f)
cornerAnimator.duration = 1000
widthAnimator.duration = 1000
progressBarAlphaAnimator.duration = 1000
cornerAnimator.addUpdateListener {
drawable?.cornerRadius = it.animatedValue as Float
binding.actionButton.background = drawable
}
widthAnimator.addUpdateListener {
binding.actionButton.updateLayoutParams {
this.width = it.animatedValue as Int
}
binding.actionButton.textSize = 1f - it.animatedFraction
}
binding.progressBar.alpha = 0f
binding.progressBar.visibility = View.VISIBLE
widthAnimator.start()
cornerAnimator.start()
progressBarAlphaAnimator.start()
}