定义自定义动画
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
此页面已弃用。有关过去位于此处的文档所在的新位置,请参阅下文。
自定义轻触反馈
Material Design 中的轻触反馈可在用户与界面元素互动时,在接触点上提供即时视觉确认。按钮的默认轻触反馈动画使用新的 RippleDrawable
类,该类会以波纹效果实现不同状态间的过渡。
在大多数情况下,您应在视图 XML 中应用此功能,方法是将视图背景指定为:
?android:attr/selectableItemBackground
,表示有界的波纹。
?android:attr/selectableItemBackgroundBorderless
,适用于越过视图边界的波纹。它将在该视图的最近父视图(具有非空背景)上进行绘制并由该父视图设定边界。
注意:selectableItemBackgroundBorderless
是在 API 级别 21 中引入的新属性。
或者,您也可以使用 ripple
元素将 RippleDrawable
定义为 XML 资源。
您可以为 RippleDrawable
对象指定一种颜色。如需更改默认触摸反馈颜色,请使用主题的 android:colorControlHighlight
属性。
如需了解详情,请参阅 RippleDrawable
类的 API 参考文档。
使用揭露效果
请参阅创建圆形揭露动画。
自定义 Activity 过渡
请参阅使用动画启动 Activity。
使用曲线运动
请参阅使用曲线运动。
为视图状态变化添加动画效果
请参阅使用 StateListAnimator 为视图状态变化添加动画效果。
为矢量可绘制对象添加动画效果
请参阅为可绘制图形添加动画效果。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Defining Custom Animations\n\n**This page is deprecated.** See below for the new location for\ndocumentation that used to be here.\n\nCustomize Touch Feedback\n------------------------\n\nTouch feedback in material design provides an instantaneous visual confirmation at the\npoint of contact when users interact with UI elements. The default touch feedback animations\nfor buttons use the new [RippleDrawable](/reference/android/graphics/drawable/RippleDrawable) class, which transitions\nbetween different states with a ripple effect.\n\nIn most cases, you should apply this functionality in your view XML by specifying the view\nbackground as:\n\n- `?android:attr/selectableItemBackground` for a bounded ripple.\n- `?android:attr/selectableItemBackgroundBorderless` for a ripple that extends beyond the view. It will be drawn upon, and bounded by, the nearest parent of the view with a non-null background.\n\n**Note:** `selectableItemBackgroundBorderless` is a new\nattribute introduced in API level 21.\n\nAlternatively, you can define a [RippleDrawable](/reference/android/graphics/drawable/RippleDrawable)\nas an XML resource using the `ripple` element.\n\nYou can assign a color to [RippleDrawable](/reference/android/graphics/drawable/RippleDrawable) objects. To change\nthe default touch feedback color, use the theme's `android:colorControlHighlight`\nattribute.\n\nFor more information, see the API reference for the [RippleDrawable](/reference/android/graphics/drawable/RippleDrawable) class.\n\nUse the Reveal Effect\n---------------------\n\nSee [Create a circular reveal animation](/training/animation/reveal-or-hide-view#Reveal).\n\n\nCustomize Activity Transitions\n------------------------------\n\nSee [Start an Activity with an Animation](/training/transitions/start-activity).\n\nUse Curved Motion\n-----------------\n\nSee [Use curved motion](/training/animation/reposition-view#CurvedMotion).\n\nAnimate View State Changes\n--------------------------\n\nSee [Using StateListAnimator to\nanimate view state changes](/guide/topics/graphics/prop-animation#ViewState).\n\nAnimate Vector Drawables\n------------------------\n\nSee [Animate Drawable Graphics](/guide/topics/graphics/drawable-animation)."]]