Skip to content

The projects and the materials that accompany the Android Animations video course

License

Notifications You must be signed in to change notification settings

YamamotoDesu/Android-Animations-raywenderlich

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android Animations: Materials

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.

Release History

Branch Version Release Date
versions/2.0 2.0 2020-12-08
versions/1.0 1.0 2018-03-26

View Property Animations

スクリーンショット 2022-06-19 14 38 24

  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()
    

Object Property Animations

    val progressBarAlphaAnimator = ObjectAnimator.ofFloat(binding.progressBar,"alpha", 0f, 1f)
    progressBarAlphaAnimator.duration = 3000
    progressBarAlphaAnimator.interpolator = BounceInterpolator()
    
    progressBarAlphaAnimator.start()

Custom Animation

  @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()
  }

About

The projects and the materials that accompany the Android Animations video course

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%