RecyclerView item animation & self-contained MotionScene

This is going to be the result after we finish with the RecyclerViewitem animations and the self-contained MotionScenes.

But for now let's focus in putting everything into place. By the end of this step you'll have created the screen below. Simple as it is right now, it's the base for us to work with.

In a RecyclerView we can customize the way it appears as a ViewGroup (enter animation), or animate the differences in its children (add/ remove item). Together we're going to see the second one.

As mentioned in the beginning of this workshop, there are 2 ways you can specify an animation; either from the code or from the XML and the RecyclerView animations are not any different than this. In this workshop we're going to create them through XML.

Let's start by adding some logic to our DetailActivity to prepare for adding our new animations.

We've put almost everything into place!

Right now, it doesn't do much since we haven't added the adapter yet but let's rewind what we've done so far.

  • We added 2 buttons in our Detail Activity layout; one for adding items and one for removing

  • We also added a counter so that we know how many items we've added and removed

  • We added a RecyclerView to our Detail Activity layout

  • And finally we created the layout for our list item of that RecyclerView. You may have noticed that in contrast with our previous motion layouts, in this one we haven't specified any constraints. The reason for this is because we are going to add our view constraints from our MotionScene XML file. We call this MotionScene "self-contained" since all the ConstraintSets are maintained in a single file.

circle-info

The upcoming MotionEditor in Android Studio will likely to only support self-contained MotionScene files.

The upcoming MotionLayout editor in Android Studio. Image from "Introduction to MotionLayout - Google Developers"

Last updated