relative to anchor points on other views or the parent layout so that constraints are satisfied. • API 9+ • Current version 1.1.3 • Included in the Support Library. • Android Studio 3.x - visual layout editor • Maintains a flat hierarchy which allows constraints to be easily modified • Constraints are embedded within the layout file.
into a separate file from the layouts themselves. • ConstrainLayout 2.0 now includes a new tool for adding motion - MotionLayout. • API 14+ • MotionLayout extends ConstraintLayout so can be a drop in replacement if you want to get started slowly. • MotionLayout uses MotionScenes to manage the animation between different ConstraintSets. • MotionScenes also let you animate custom attributes. • MotionScenes allow you to interpolate the animations between states based on user input e.g. dragging.
you’re using androidx the package names will be slightly different. <android.support.constraint.motion.MotionLayout app:layoutDescription="@xml/scene_keyframe" app:showPaths="true"> </android.support.constraint.motion.MotionLayout> layout/layout_keyframe.xml
for OnSwipe and OnClick • OnSwipe interacts with user touches. • OnClick responds to clicks • You can have OnSwipe and OnClick both defined in the MotionScene, but OnClick will no longer work if OnSwipe is defined.* • You can also trigger transitions programatically. * more news on this later.
for a widget, whereas a ConstraintSet defines a “resting” state. • Keyframes are very lightweight compared to ConstraintSets • KeyPositions allow you to modify the path a widget will take during a transition.
examples that <KeyPosition> motion:percentY moves the path in what looks like the x axis. • The reason for this is because of the coordinate system being used - pathRelative • Keyframes can use different coordinate systems for different widgets.
to add a keyframe for a position, it allows you to add a keyframe for an attribute. • visibility • alpha • elevation • rotation • rotationX/Y • scaleX/Y • translationX/Y/Z <KeyAttribute android:rotation="45" motion:framePosition="50" motion:target="@id/text" />
want to modify needs to have a get/set method in the form get<AttributeName> e.g. getBackgroundColor • Values that can be altered • Color • Integer • Float • String • Dimension • Boolean <KeyAttribute motion:framePosition="50" motion:target="@id/text"> <CustomAttribute motion:attributeName="backgroundColor" motion:customColorValue="#0000FF"/> </KeyAttribute>
scared! It builds upon the stable v1.1 • Alpha 2 contains breaking changes from Alpha 1, to avoid namespace clash with Navigation components. Android Studio 3.4 should contain the new Keyframe editor demoed at Google I/O 2018 <KeyPosition motion:type=“pathRelative"/> <KeyPosition motion:keyPositionType="pathRelative"/>