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

Creating a self-contained MotionScene

The only difference between the main structure of the self-contained MotionScene and the one we saw before is that the ConstraintSets are described in this file instead of just referring to the layout IDs

Let's create a new MotionScene called motion_scene_detail.xml. For now let's copy-paste the same MotionLayout we created for the Main Activity (motion_scene_main.xml)

motion_scene_detail.xml
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:app="http://schemas.android.com/apk/res-auto">
    <Transition
        app:constraintSetEnd="@layout/activity_main_end"
        app:constraintSetStart="@layout/activity_main_start"
        app:duration="1000">

        <OnSwipe
            app:dragDirection="dragUp"
            app:touchAnchorId= "@id/second_bg"
            app:touchAnchorSide="top" />
    </Transition>
</MotionScene>

We're not going to use the gesture handler so we can delete that. Additionally, instead of setting our constraints from the layout we mentioned that we're going to include our constraints here. To do so we need to specify aConstraintSet for the start and one for the end. Inside those ConstraintSets we'll include the Constraints of our view(s). To add the "spin" we will add to our Constraint a rotation attribute.

Once you're done you'll have again to add it as a layoutDescription in the item layout XML.

PreviousRecyclerView item animation & self-contained MotionSceneNextCreating a self-contained MotionScene : Solution

Last updated 6 years ago