MotionLayout allows defining animations in XML without code by extending ConstraintLayout. It uses a MotionScene file to specify animation properties like start and end states as ConstraintSets. Custom attributes can also be used to change view properties like color during an animation triggered by user input. The animation defined in MotionScene takes precedence over any defined in the layout file.