Stay organized with collections Save and categorize content based on your preferences.

Specifies location and attributes for views over the course of the motion sequence. By default, motion proceeds from the initial state to the end state; by using <KeyFrameSet>, you can build more complex motions. The <KeyFrameSet> contains <KeyPosition> or <KeyAttribute> nodes. Each of those nodes specifies the position or attributes of a target view at a specific point in the motion. MotionLayout smoothly animates the view from the starting point to each of those intermediate points, and then to the final destination.

For example, suppose the initial state of the motion sequence has an opaque ball in the lower left corner of the view, and the final state has the ball in the upper right corner and entirely transparent. By default, the MotionLayout would move the ball smoothly in a diagonal line, gradually becoming more transparent until it vanishes when it reaches its destination. By using <KeyFrameSet>, you can change this behavior. For example, you might set the ball to move vertically to the upper left corner while remaining entirely opaque, then move horizontally to the upper right corner while fading out. You would do this by creating a <KeyFrameSet>, and adding a <KeyPosition> and a <KeyAttribute> inside it. The <KeyPosition> would specify the intermediate location of the ball, and the <KeyAttribute> would specify that the ball remains opaque at the midpoint of the motion.


    [ <KeyPosition/>... ]
    [ <KeyAttribute/>...]

Contained in