[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Introduction to animations\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to use Animations in Compose. \n[Animations in Compose →](/jetpack/compose/animation) \n\n\u003cbr /\u003e\n\nAnimations can add visual cues that notify users about what's going on in your\napp. They are especially useful when the UI changes state, such as when new\ncontent loads or new actions become available. Animations also add a polished\nlook to your app, which gives it a higher quality look and feel.\n\nAndroid includes different animation APIs depending on what type of animation\nyou want. This documentation provides an overview of the different ways you can\nadd motion to your UI.\n\nTo better understand when you should use animations, also see the [Material\nDesign guide about motion](https://www.google.com/url?sa=D&q=https%3A%2F%2Fm3.material.io%2Fstyles%2Fmotion%2Foverview).\n| **Note:** For guidance on animations in Jetpack Compose, see [Animation](https://developer.android.com/jetpack/compose/animation).\n\nAnimate bitmaps\n---------------\n\n**Figure 1.** An animated drawable.\n\nTo animate a bitmap graphic such as an icon or illustration, use the drawable\nanimation APIs. Usually, these animations are defined statically with a drawable\nresource, but you can also define the animation behavior at runtime.\n\nFor example, a nice way to communicate to the user that two actions are related\nis to animate a play button that transforms into a pause button when it's\ntapped.\n\nFor more information, read [Animate drawable graphics](/guide/topics/graphics/drawable-animation).\n\nAnimate UI visibility and motion\n--------------------------------\n\n**Figure 2.** A subtle animation when a dialog appears\nand disappears makes the UI change less jarring.\n\nWhen you need to change the visibility or position of views in your layout, it's\nbest to include subtle animations to help the user understand how the UI is\nchanging.\n\nTo move, reveal, or hide views within the current layout, you can use the\nproperty animation system provided by the [`android.animation`](/reference/android/animation/package-summary) package, available in Android 3.0\n(API level 11) and higher. These APIs update the properties of your [`View`](/reference/android/view/View) objects over a period of time, continuously\nredrawing the view as the properties change. For example, when you change the\nposition properties, the view moves across the screen. When you change the alpha\nproperty, the view fades in or out.\n\nFor the simplest way to create these animations, enable animations on your\nlayout so that when you change the visibility of a view, an animation applies\nautomatically. For more information, see [Auto animate layout updates](/training/animation/layout).\n\nTo learn how to build animations using the property animation system, read the\n[Property animation overview](/guide/topics/graphics/prop-animation). You\ncan also see the following pages to create common animations:\n\n- [Change a view visibility with a crossfade](/training/animation/reveal-or-hide-view#Crossfade).\n\n- [Change a view visibility with a circular reveal](/training/animation/reveal-or-hide-view#Reveal).\n\n- [Swap views with a card flip](/training/animation/reveal-or-hide-view#Cardflip).\n\n- [Change the view size with a zoom animation](/training/animation/zoom).\n\n### Physics-based motion\n\n**Figure 3.** Animation built with ObjectAnimator. \n\n**Figure 4.** Animation built with physics-based\nAPIs.\n\nWhenever possible, apply real-world physics to your animations so that they are\nnatural-looking. For example, they should maintain momentum when their target\nchanges and make smooth transitions during any changes.\n\nTo provide these behaviors, the Android Support library includes physics-based\nanimation APIs that rely on the laws of physics to control how your animations\noccur.\n\nTwo common physics-based animations are the following:\n\n- [Spring animation](/develop/ui/views/animations/spring-animation).\n\n- [Fling animation](/develop/ui/views/animations/fling-animation).\n\nAnimations not based on physics---such as those built with [`ObjectAnimator`](/reference/android/animation/ObjectAnimator) APIs---are fairly static and have a\nfixed duration. If the target value changes, you must cancel the animation at\nthe time of target value change, re-configure the animation with a new value as\nthe new start value, and add the new target value. Visually, this process\ncreates an abrupt stop in the animation, and a disjointed movement afterwards,\nas shown in figure 3.\n\nAnimations built by with physics-based animation APIs, such as\n[`DynamicAnimation`](/reference/androidx/dynamicanimation/animation/DynamicAnimation), are driven by\nforce. The change in the target value results in a change in force. The new\nforce applies on the existing velocity, which makes a continuous transition to\nthe new target. This process results in a more natural-looking animation, as\nshown in figure 4.\n\nAnimate layout changes\n----------------------\n\n\n**Figure 5.** An animation to show more details can be achieved by\neither changing the layout or starting a new activity.\n\nOn Android 4.4 (API level 19) and higher, you can use the transition framework\nto create animations when you swap the layout within the current activity or\nfragment. All you need to do is specify the starting and ending layout and what\ntype of animation you want to use. Then the system figures out and executes an\nanimation between the two layouts. You can use this to swap out the entire UI or\nto move or replace just some views.\n\nFor example, when the user taps an item to see more information, you can replace\nthe layout with the item details, applying a transition like the one shown in\nfigure 5.\n\nThe starting and ending layout are each stored in a\n[`Scene`](/reference/android/transition/Scene), though the starting scene is\nusually determined automatically from the current layout. You create a\n[`Transition`](/reference/android/transition/Transition) to tell the system what\ntype of animation you want, then call\n[`TransitionManager.go()`](/reference/android/transition/TransitionManager#go(android.transition.Scene,%20android.transition.Transition))\nand the system runs the animation to swap the layouts.\n\nFor more information, read [Animate layout changes using a transition](/develop/ui/views/animations/transitions). For sample code, check out\n[BasicTransition](https://github.com/android/animation-samples/tree/main/BasicTransition)\n.\n\nAnimate between activities\n--------------------------\n\nOn Android 5.0 (API level 21) and higher, you can also create animations that\ntransition between your activities. This is based on the same transition\nframework described in the previous section, but it lets you create animations\nbetween layouts in *separate activities*.\n\nYou can apply simple animations such as sliding the new activity in from the\nside or fading it in, but you can also create animations that transition between\nshared views in each activity. For example, when the user taps an item to see\nmore information, you can transition into a new activity with an animation that\nseamlessly grows that item to fill the screen, like the animation shown in\nfigure 5.\n\nAs usual, you call\n[`startActivity()`](/reference/android/app/Activity#startActivity(android.content.Intent)),\nbut pass it a bundle of options provided by\n[`ActivityOptions.makeSceneTransitionAnimation()`](/reference/android/app/ActivityOptions#makeSceneTransitionAnimation(android.app.Activity,%20android.view.View,%20java.lang.String)).\nThis bundle of options might include which views are shared between the\nactivities so the transition framework can connect them during the animation.\n\nFor additional resources, see:\n\n- [Start an activity using an animation](/training/transitions/start-activity)\n- [ActivitySceneTransitionBasic](https://github.com/android/animation/tree/main/ActivitySceneTransitionBasic)"]]