Animation sets in Android

In previous sections, we worked with animations from resources defined in XML. In this section, we will play with various view attributes and with animation sets. We will illustrate the purpose and use with simple and effective examples.

Let's demonstrate the first animation from the code. Open ItemsFragment. Add the following method:

     private fun animate(btn: FloatingActionButton, expand: Boolean =     true) { 
        btn.animate() 
                .setInterpolator(BounceInterpolator()) 
                .scaleX(if(expand){ 1.5f } else { 1.0f }) 
                .scaleY(if(expand){ 1.5f } else { 1.0f }) 
                .setDuration(2000) 
                .start() 
      } 

What this method will do? This method will animate scaling for the button with bounce interpolation. If the expand parameter is true, we will scale ...

Get Mastering Android Development with Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.