[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Build animation with the Motion Editor\n\nAndroid Studio includes a visual design editor for the\n[MotionLayout](/training/constraint-layout/motionlayout) layout type, making it\neasier to create and preview animations.\n\nThe Motion Editor provides a simple interface for manipulating elements from the\nMotionLayout library that serves as the foundation for animation in Android\napps. Without Android Studio, creating and altering these elements requires\nmanually editing constraints in XML resource files. The Motion Editor, however,\ncan generate this XML for you, with support for start and end states, keyframes,\ntransitions, and timelines.\n| **Note:** Before using the Motion Editor, be sure to set the `ConstraintLayout` dependency in your `build.gradle` file to version `2.0.0-beta3`, as described in the MotionLayout [reference documentation](/training/constraint-layout/motionlayout#getting_started).\n\nTo get started with the Motion Editor:\n\n1. [Create a ConstraintLayout](/training/constraint-layout#add-constraintlayout-to-your-project).\n2. Right-click on the preview in the Layout Editor.\n3. Click **Convert to MotionLayout**, as shown below.\n\nAfter Android Studio converts your ConstraintLayout to MotionLayout, a Motion\nScene file (an `.xml` file with `_scene` appended to your layout filename) is\nalso added to the directory containing your XML.\n\nThe `MotionLayout` then becomes your root layout, and it appears in the Motion\nEditor UI. The layout already includes a start `ConstraintSet`, end\n`ConstraintSet`, and a transition going from start to end.\n\nYou can use the overview graphic to select a `ConstraintSet` or\n`Transition` and to select components on the selection panel.\n\nThen you can edit the constraints and attributes of either the start or end\n`ConstraintSet` the same way you would edit a `ConstraintLayout`.\n\nIf you want to build more elements to your graph, you can use the creation\nicons to quickly add a `ConstraintSet`, `Transition`, or `OnClick`/`OnSwipe`\ngestures.\n\nTo add a keyframe, first click on the **Transition** arrow:\n\nThen, in the **Transition** timeline pane, click on the top-right corner and\nselect **KeyPosition**:\n\nThis action opens a dialog where you can set attributes for the keyframe.\n\nYou can also add `OnClick` and `OnSwipe` handlers to the Transition in the\nattribute panel.\n\nThis action opens a dialog where you can set attributes of the click such as\ntarget components and drag direction.\n\nThe Motion Editor supports previewing animations on the design surface. When an\nanimation is selected, click **Play**\n\nabove the timeline to preview the animation."]]