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.

Last updated