Animations in Android
  • Introduction
  • About us
  • Basic animations
  • ConstraintLayout: Core concepts
  • I like to move it, move it!
  • Step 1
  • Step 2
  • Step 2: Solution
  • Step 3
  • Step 3: Solution
  • Step 4
  • Step 4: Solution
  • Step 5
  • Step 5: Solution
  • Step 6
  • Step 7
  • Step 7: Solution
  • Step 8
  • Step 8: Solution
  • MotionLayout
  • Party time!
  • Shared element transition
  • Adding a RecyclerView
  • Activity transitions
  • Adding a second Activity
  • Adding the shared element transition
  • You made it!
  • VectorDrawable
  • VectorDrawable: Solution
  • Using the VectorDrawable
  • RecyclerView item animation & self-contained MotionScene
  • Creating a self-contained MotionScene
  • Creating a self-contained MotionScene : Solution
  • Adding animations in the RecyclerView items: Step 1
  • Adding animations in the RecyclerView items: Step 2
  • RecyclerView animations step 2: Solution
  • Physic based animations
  • Implement a spring animation
  • Spring animation: Solution
  • The finish line!
Powered by GitBook
On this page

Using the VectorDrawable

We are first going to create our Drawables variables in the DetailActivity.kt

val animDrawable = getDrawable(R.drawable.avd_edit_done) as AnimatedVectorDrawable
val animDrawable2 = getDrawable(R.drawable.avd_done_edit) as AnimatedVectorDrawable

And then we need to assign the drawables to our FAB like this:

DetailActivity.kt
private var isEditMode = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ...
        fab.setImageDrawable(animDrawable)
        fab.setOnClickListener {
            if (!isEditMode) {
                fab.setImageDrawable(animDrawable)
                (fab.drawable as Animatable).start()
            } else {
                fab.setImageDrawable(animDrawable2)
                (fab.drawable as Animatable).start()
            }
            isEditMode= !isEditMode
        }
    }

Note that we're also using a flag to know when we should turn our FAB icon into a pencil or a check mark.

PreviousVectorDrawable: SolutionNextRecyclerView item animation & self-contained MotionScene

Last updated 6 years ago