【翻译】(33)动画资源

【翻译】(33)动画资源

 

see

http://developer.android.com/guide/topics/resources/animation-resource.html

 

原文见

http://developer.android.com/guide/topics/resources/animation-resource.html

 

-------------------------------

 

Animation Resources

 

动画资源

 

-------------------------------

 

In this document

 

本文目录

 

* Property Animation 属性动画

* View Animation 视图动画

* Tween animation 补间动画

* Frame animation 帧动画

 

See also

 

另见

 

View Animation 视图动画

Property Animation 属性动画

 

-------------------------------

 

An animation resource can define one of two types of animations:

 

一个动画资源可以定义两种类型的动画之一:

 

* Property Animation

 

* 属性动画

 

Creates an animation by modifying an object's property values over a set period of time with an Animator.

 

通过用一个Animator在一组周期时间上修改对象的属性值来创建一个动画

 

* View Animation

 

* 视图动画

 

There are two types of animations that you can do with the view animation framework:

 

你可以用视图动画框架处理两种类型的动画:

 

* Tween animation: Creates an animation by performing a series of transformations on a single image with an Animation

 

* 补间动画(注:Tween在维基上作Inbetweening,也可以理解为把between名词化):通过用一个Animation对象在一个单一图片上执行一系列转换来创建一个动画

 

* Frame animation: or creates an animation by showing a sequence of images in order with an AnimationDrawable.

 

* 帧动画:或者通过用一个AnimationDrawable对象依次地显示一连串图片来创建一个动画。

 

-------------------------------

 

Property Animation

 

属性动画

 

An animation defined in XML that modifies properties of the target object, such as background color or alpha value, over a set amount of time.

 

一个定义在XML中的动画在一定数量的时间期间修改目标对象的属性,诸如背景颜色或透明度值。

 

* file location:

 

文件位置:

 

res/animator/filename.xml

 

res/animator/<文件名>.xml

 

The filename will be used as the resource ID.

 

文件名将被用于资源ID。

 

* compiled resource datatype:

 

* 被编译的资源数据类型:

 

Resource pointer to a ValueAnimator, ObjectAnimator, or AnimatorSet.

 

指向一个ValueAnimator,ObjectAnimator或AnimatorSet的资源指针

 

* resource reference:

 

* 资源引用:

 

In Java: R.animator.filename

 

在Java中:R.animator.<文件名>

 

In XML: @[package:]animator/filename

 

在XML中:@[<包名>:]animator/<文件名>

 

* syntax:

 

* 语法:

 

-------------------------------

 

<set

  android:ordering=["together" | "sequentially"]>

 

    <objectAnimator

        android:propertyName="string"

        android:duration="int"

        android:valueFrom="float | int | color"

        android:valueTo="float | int | color"

        android:startOffset="int"

        android:repeatCount="int"

        android:repeatMode=["repeat" | "reverse"]

        android:valueType=["intType" | "floatType"]/>

 

    <animator

        android:duration="int"

        android:valueFrom="float | int | color"

        android:valueTo="float | int | color"

        android:startOffset="int"

        android:repeatCount="int"

        android:repeatMode=["repeat" | "reverse"]

        android:valueType=["intType" | "floatType"]/>

 

    <set>

        ...

    </set>

</set>

 

-------------------------------

 

The file must have a single root element: either <set>, <objectAnimator>, or <valueAnimator>. You can group animation elements together inside the <set> element, including other <set> elements.

 

文件必须有一个单一的根元素:<set>,<objectAnimator>或<valueAnimator>。你可以把动画元素分组在一起放在<set>元素内,包含其它<set>元素。

 

* elements:

 

* 元素:

 

* <set>

 

A container that holds other animation elements (<objectAnimator>, <valueAnimator>, or other <set> elements). Represents an AnimatorSet.

 

一个容器,它持有其它动画元素(<objectAnimator>,<valueAnimator>,或其它<set>元素)。代表一个AnimatorSet。

 

You can specify nested <set> tags to further group animations together. Each <set> can define its own ordering attribute.

 

你可以指定嵌套的<set>标签以更深入地把动画分组在一起。每个<set>可以定义它自己的ordering属性。

 

* attributes:

 

* 属性:

 

* android:ordering

 

Keyword. Specifies the play ordering of animations in this set.

 

关键词。指定在这个集合中的动画的播放次序。

 

-------------------------------

 

Value Description

 

值 描述

 

* sequentially Play animations in this set sequentially

 

* 串行 串行地播放这个集合中的动画

 

* together (default) Play animations in this set at the same time.

 

* 一起(默认) 同时地播放这个集合中的动画。

 

-------------------------------

 

* <objectAnimator>

 

Animates a specific property of an object over a specific amount of time. Represents an ObjectAnimator.

 

在指定数量的时间内动画化一个对象的指定属性。代表一个ObjectAnimator。

 

attributes:

 

属性:

 

* android:propertyName

 

String. Required. The object's property to animate, referenced by its name. For example you can specify "alpha" or "backgroundColor" for a View object. The objectAnimator element does not expose a target attribute, however, so you cannot set the object to animate in the XML declaration. You have to inflate your animation XML resource by calling loadAnimator() and call setTarget() to set the target object that contains this property.

 

字符串。必需的。要动画化的对象属性,通过它的名称来引用。例如你可以指定一个View对象的"alpha"或"backgroundColor"。然而,objectAnimator元素不暴露target属性,所以你不能在XML声明中设置要动画化的对象。你必须通过调用loadAnimator()解压你的动画XML资源,并且调用setTarget()以设置包含这个属性的目标对象。

 

* android:valueTo

 

float, int, or color. Required. The value where the animated property ends. Colors are represented as six digit hexadecimal numbers (for example, #333333).

 

浮点型,整型,或颜色。必需的。动画化属性结束处的值。颜色用一个六位十六进制数表示(例如,#333333)。

 

* android:valueFrom

 

float, int, or color. The value where the animated property starts. If not specified, the animation starts at the value obtained by the property's get method. Colors are represented as six digit hexadecimal numbers (for example, #333333).

 

浮点型,整型,或颜色。动画化属性开始处的值。如果不指定,动画开始于被属性的get方法获取的值。颜色用一个六位十六进制数表示(例如,#333333)。

 

* android:duration

 

int. The time in milliseconds of the animation. 300 milliseconds is the default.

 

整型。动画的毫秒时间。默认为300毫秒。

 

* android:startOffset

 

int. The amount of milliseconds the animation delays after start() is called.

 

整型。动画在start()被调用后延迟的毫秒数。

 

* android:repeatCount

 

int. How many times to repeat an animation. Set to "-1" to infinitely repeat or to a positive integer. For example, a value of "1" means that the animation is repeated once after the initial run of the animation, so the animation plays a total of two times. The default value is "0", which means no repetition.

 

整型。动画重复的次数。设置为"-1"以无限地重复或设置为一个正整数。例如,"1"值的意思是动画在动画最开始运行后重复一次,所以动画总共播放两次。默认值为"0",意思是没有重复。

 

* android:repeatMode

 

int. How an animation behaves when it reaches the end of the animation. android:repeatCount must be set to a positive integer or "-1" for this attribute to have an effect. Set to "reverse" to have the animation reverse direction with each iteration or "repeat" to have the animation loop from the beginning each time.

 

整型。当它到达动画的结束时一个动画如何行为。android:repeatCount必须被设置为一个正整数或"-1",才能使这个属性有效。设置为"reverse"使动画在每次迭代时反方向,或者设置为"repeat"让动画每次开始时从开始处循环回圈。

 

* android:valueType

 

Keyword. Do not specify this attribute if the value is a color. The animation framework automatically handles color values

 

关键词。不要指定这个属性,如果值为颜色。动画框架自动地处理颜色值。

 

-------------------------------

 

Value Description

 

值 描述

 

intType Specifies that the animated values are integers

 

intType 指定动画化的值是整型

 

floatType (default) Specifies that the animated values are floats

 

floatType(默认) 指定动画化的值是浮点型

 

-------------------------------

 

* <animator>

 

Animates a over a specified amount of time. Represents a ValueAnimator.

 

在一个指定数量的时间内的动画。代表一个ValueAnimator。

 

attributes:

 

属性:

 

* android:valueTo

 

float, int, or color. Required. The value where the animation ends. Colors are represented as six digit hexadecimal numbers (for example, #333333).

 

浮点型,整型,或颜色。必需的。动画结束处的值。颜色用一个六位十六进制数表示(例如,#333333)。

 

* android:valueFrom

 

float, int, or color. Required. The value where the animation starts. Colors are represented as six digit hexadecimal numbers (for example, #333333).

 

浮点型,整型,或颜色。动画开始处的值。颜色用一个六位十六进制数表示(例如,#333333)。

 

* android:duration

 

int. The time in milliseconds of the animation. 300ms is the default.

 

整型。动画的毫秒单位时间。默认为300毫秒。

 

* android:startOffset

 

int. The amount of milliseconds the animation delays after start() is called.

 

整型。动画在start()调用后的延迟毫秒数。

 

* android:repeatCount

 

int. How many times to repeat an animation. Set to "-1" to infinitely repeat or to a positive integer. For example, a value of "1" means that the animation is repeated once after the initial run of the animation, so the animation plays a total of two times. The default value is "0", which means no repetition.

 

整型。动画重复的次数。设置为"-1"以无限地重复或设置为正整数。例如,"1"值的意思是动画在动画最开始运行后被重复一次,所以动画总共播放两次。默认值为"0",意思是无重复。

 

* android:repeatMode

 

int. How an animation behaves when it reaches the end of the animation. android:repeatCount must be set to a positive integer or "-1" for this attribute to have an effect. Set to "reverse" to have the animation reverse direction with each iteration or "repeat" to have the animation loop from the beginning each time.

 

整型。当它达到动画的结束时,一个动画如何行为。ndroid:repeatCount必须被设置为整型或"-1",这个属性才有效。设置为"reverse"以让动画在每次迭代时反方向或设置为"repeat"让动画每次从头开始循环回圈。

 

* android:valueType

 

Keyword. Do not specify this attribute if the value is a color. The animation framework automatically handles color values.

 

关键词。如果值为颜色,不指定这个属性。动画框架自动地处理颜色值。

 

-------------------------------

 

Value Description

 

值 描述

 

intType Specifies that the animated values are integers

 

intType 指定动画化的值为整型

 

floatType (default) Specifies that the animated values are floats

 

floatType(默认) 指定动画化的值为浮点型

 

-------------------------------

 

example:

 

示例:

 

XML file saved at res/animator/property_animator.xml:

 

XML文件保存在res/animator/property_animator.xml:

 

-------------------------------

 

<set android:ordering="sequentially">

    <set>

        <objectAnimator

            android:propertyName="x"

            android:duration="500"

            android:valueTo="400"

            android:valueType="intType"/>

        <objectAnimator

            android:propertyName="y"

            android:duration="500"

            android:valueTo="300"

            android:valueType="intType"/>

    </set>

    <objectAnimator

        android:propertyName="alpha"

        android:duration="500"

        android:valueTo="1f"/>

</set>

 

-------------------------------

 

In order to run this animation, you must inflate the XML resources in your code to an AnimatorSet object, and then set the target objects for all of the animations before starting the animation set. Calling setTarget() sets a single target object for all children of the AnimatorSet as a convenience. The following code shows how to do this:

 

为了运行这个动画,你必须在你的代码中解压XML资源到一个AnimatorSet对象,然后在开始动画集之前设置所有动画的目标对象。方便起见,调用setTarget()为所有AnimatorSet的子对象设置单一的目标对象。以下代码展示如何做到这点:

 

-------------------------------

 

AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,

    R.anim.property_animator);

set.setTarget(myObject);

set.start();

 

-------------------------------

 

see also:

 

另见:

 

* Property Animation

 

* 属性动画

 

* API Demos for examples on how to use the property animation system.

 

* API演示中获取关于如何使用属性动画系统的示例。

 

-------------------------------

 

View Animation

 

视图动画

 

The view animation framework supports both tween and frame by frame animations, which can both be declared in XML. The following sections describe how to use both methods.

 

视图动画框架支持补间和逐帧的动画,它们都可以在XML中声明。以下章节描述如何使用这两种方法。

 

Tween animation

 

补间动画

 

An animation defined in XML that performs transitions such as rotating, fading, moving, and stretching on a graphic.

 

一个定义在XML中的动画执行转换诸如在一个图形上的旋转,淡出,移动,以及拉伸。

 

* file location:

 

* 文件位置:

 

res/anim/filename.xml

 

res/anim/<文件名>.xml

 

The filename will be used as the resource ID.

 

文件名将被用作资源ID。

 

* compiled resource datatype:

 

* 被编译的资源数据类型:

 

Resource pointer to an Animation.

 

指向一个Animation的资源指针。

 

* resource reference:

 

* 资源引用:

 

* In Java: R.anim.filename

 

* 在Java中:R.anim.<文件名>

 

* In XML: @[package:]anim/filename

 

* 在XML中:@[<包名>:]anim/<文件名>

 

syntax:

 

语法:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"

    android:interpolator="@[package:]anim/interpolator_resource"

    android:shareInterpolator=["true" | "false"] >

    <alpha

        android:fromAlpha="float"

        android:toAlpha="float" />

    <scale

        android:fromXScale="float"

        android:toXScale="float"

        android:fromYScale="float"

        android:toYScale="float"

        android:pivotX="float"

        android:pivotY="float" />

    <translate

        android:fromXDelta="float"

        android:toXDelta="float"

        android:fromYDelta="float"

        android:toYDelta="float" />

    <rotate

        android:fromDegrees="float"

        android:toDegrees="float"

        android:pivotX="float"

        android:pivotY="float" />

    <set>

        ...

    </set>

</set>

 

-------------------------------

 

The file must have a single root element: either an <alpha>, <scale>, <translate>, <rotate>, or <set> element that holds a group (or groups) of other animation elements (even nested <set> elements).

 

文件必须有一个单一的根元素:<alpha>,<scale>,<translate>,<rotate>或持有一组(或多组)其它动画元素的<set>元素(甚至内嵌的<set>元素)。

 

elements:

 

元素:

 

* <set>

 

A container that holds other animation elements (<alpha>, <scale>, <translate>, <rotate>) or other <set> elements. Represents an AnimationSet.

 

一个容器,持有其它动画元素(<alpha>,<scale>,<translate>,<rotate>)或者其它<set>元素。代表一个AnimationSet。

 

attributes:

 

属性:

 

* android:interpolator

 

Interpolator resource. An Interpolator to apply on the animation. The value must be a reference to a resource that specifies an interpolator (not an interpolator class name). There are default interpolator resources available from the platform or you can create your own interpolator resource. See the discussion below for more about Interpolators.

 

插值器资源。一个应用在动画上的插值器。值必须是指向指定一个插值器的资源的引用(不是插值器类名)。从平台中有默认可用的插值器资源,或者你可以创建你自己的插值器资源。参见下面的讨论以获取更多关于插值器的信息。

 

* android:shareInterpolator

 

Boolean. "true" if you want to share the same interpolator among all child elements.

 

布尔型。设置为"true"如果你希望在所有子元素之间共享相同的插值器。

 

* <alpha>

 

A fade-in or fade-out animation. Represents an AlphaAnimation.

 

一个淡入或淡出动画。代表一个AlphaAnimation。

 

attributes:

 

属性:

 

* android:fromAlpha

 

Float. Starting opacity offset, where 0.0 is transparent and 1.0 is opaque.

 

浮点型。开始的不透明度偏移,0.0是透明,而1.0是不透明。

 

* android:toAlpha

 

Float. Ending opacity offset, where 0.0 is transparent and 1.0 is opaque.

 

浮点型。结束的不透明度偏移,0.0是透明,而1.0是不透明。

 

For more attributes supported by <alpha>, see the Animation class reference (of which, all XML attributes are inherrited by this element).

 

想获取<alpha>支持的更多属性,请参见Animation类参考文档(这个元素继承它的所有XML属性)。

 

* <scale>

 

A resizing animation. You can specify the center point of the image from which it grows outward (or inward) by specifying pivotX and pivotY. For example, if these values are 0, 0 (top-left corner), all growth will be down and to the right. Represents a ScaleAnimation.

 

一个改变大小的动画。你可以指定图片的中点,它从它开始向外(或向内)生长,通过指定的pivotX和pivotY。(注:pivot是轴心的意思)。例如,这些值为0, 0(左上角),所有生长将向下和向右。代表一个ScaleAnimation。

 

attributes:

 

属性:

 

* android:fromXScale

 

Float. Starting X size offset, where 1.0 is no change.

 

浮点型。开始的X大小偏移,1.0为无改变。

 

* android:toXScale

 

Float. Ending X size offset, where 1.0 is no change.

 

浮点型。结束的X大小偏移,1.0为无改变。

 

* android:fromYScale

 

Float. Starting Y size offset, where 1.0 is no change.

 

浮点型。开始的Y大小偏移,1.0为无改变。

 

* android:toYScale

 

Float. Ending Y size offset, where 1.0 is no change.

 

浮点型。结束的Y大小偏移,1.0为无改变。

 

* android:pivotX

 

Float. The X coordinate to remain fixed when the object is scaled.

 

浮点型。当大小被缩放时维持固定的X坐标。

 

* android:pivotY

 

Float. The Y coordinate to remain fixed when the object is scaled.

 

浮点型。当大小被缩放时维持固定的Y坐标。

 

For more attributes supported by <scale>, see the Animation class reference (of which, all XML attributes are inherrited by this element).

 

想获取<scale>支持的更多属性,参见Animation类参考文档(这个元素继承它的所有XML属性)。

 

* <translate>

 

A vertical and/or horizontal motion. Supports the following attributes in any of the following three formats: values from -100 to 100 ending with "%", indicating a percentage relative to itself; values from -100 to 100 ending in "%p", indicating a percentage relative to its parent; a float value with no suffix, indicating an absolute value. Represents a TranslateAnimation.

 

一个垂直和/或水平平移。支持以下三种格式中任意一种的属性:以"%"结束从-100到100的值,指示相对于它自身的百分比;以"%p"结束从-100到100的值,指示相对于它的父对象的百分比;一个不带后缀的浮点值,指示一个绝对值。代表一个TranslateAnimation。

 

attributes:

 

属性:

 

* android:fromXDelta

 

Float or percentage. Starting X offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p").

 

浮点型或百分比。开始的X偏移。代表其中之一:像素单位,相对于正常位置(诸如"5"),百分比,相对于元素的宽度(诸如"5%"),或者相对于父对象宽度的百分比(诸如"5%p")。

 

* android:toXDelta

 

Float or percentage. Ending X offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p").

 

浮点型或百分比。结束的X偏移。代表其中之一:像素单位,相对于正常位置(诸如"5"),百分比,相对于元素的宽度(诸如"5%"),或者相对于父对象宽度的百分比(诸如"5%p")。

 

* android:fromYDelta

 

Float or percentage. Starting Y offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element height (such as "5%"), or in percentage relative to the parent height (such as "5%p").

 

浮点型或百分比。开始的Y偏移。代表其中之一:像素单位,相对于正常位置(诸如"5"),百分比,相对于元素的宽度(诸如"5%"),或者相对于父对象宽度的百分比(诸如"5%p")。

 

* android:toYDelta

 

Float or percentage. Ending Y offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element height (such as "5%"), or in percentage relative to the parent height (such as "5%p").

 

浮点型或百分比。结束的Y偏移。代表其中之一:像素单位,相对于正常位置(诸如"5"),百分比,相对于元素的宽度(诸如"5%"),或者相对于父对象宽度的百分比(诸如"5%p")。

 

For more attributes supported by <translate>, see the Animation class reference (of which, all XML attributes are inherrited by this element).

 

想获取<translate>支持的更多属性,参见Animation类参考文档(这个元素继承它的所有XML属性)。

 

* <rotate>

 

A rotation animation. Represents a RotateAnimation.

 

旋转动画。代表一个RotateAnimation。

 

attributes:

 

属性:

 

* android:fromDegrees

 

Float. Starting angular position, in degrees.

 

浮点型。开始的角度位置,以度数为单位。

 

* android:toDegrees

 

Float. Ending angular position, in degrees.

 

浮点型。结束的角度位置,以度数为单位。

 

* android:pivotX

 

Float or percentage. The X coordinate of the center of rotation. Expressed either: in pixels relative to the object's left edge (such as "5"), in percentage relative to the object's left edge (such as "5%"), or in percentage relative to the parent container's left edge (such as "5%p").

 

浮点型或百分比。旋转中心的X坐标。表达其中之一:像素单位相对于对象的左边沿(诸如"5"),百分比相对于对象的左边沿(诸如"5%"),或百分比相对于父容器的左边沿(诸如"5%p")。

 

* android:pivotY

 

Float or percentage. The Y coordinate of the center of rotation. Expressed either: in pixels relative to the object's top edge (such as "5"), in percentage relative to the object's top edge (such as "5%"), or in percentage relative to the parent container's top edge (such as "5%p").

 

浮点型或百分比。旋转中心的Y坐标。表达其中之一:像素单位相对于对象的左边沿(诸如"5"),百分比相对于对象的左边沿(诸如"5%"),或百分比相对于父容器的左边沿(诸如"5%p")。

 

For more attributes supported by <rotate>, see the Animation class reference (of which, all XML attributes are inherrited by this element).

 

想获取<rotate>支持的更多属性,参见Animation类参考文档(这个元素继承它的所有XML属性)。

 

example:

 

示例:

 

XML file saved at res/anim/hyperspace_jump.xml:

 

XML文件保存在res/anim/hyperspace_jump.xml:

 

-------------------------------

 

<set xmlns:android="http://schemas.android.com/apk/res/android"

    android:shareInterpolator="false">

    <scale

        android:interpolator="@android:anim/accelerate_decelerate_interpolator"

        android:fromXScale="1.0"

        android:toXScale="1.4"

        android:fromYScale="1.0"

        android:toYScale="0.6"

        android:pivotX="50%"

        android:pivotY="50%"

        android:fillAfter="false"

        android:duration="700" />

    <set

        android:interpolator="@android:anim/accelerate_interpolator"

        android:startOffset="700">

        <scale

            android:fromXScale="1.4"

            android:toXScale="0.0"

            android:fromYScale="0.6"

            android:toYScale="0.0"

            android:pivotX="50%"

            android:pivotY="50%"

            android:duration="400" />

        <rotate

            android:fromDegrees="0"

            android:toDegrees="-45"

            android:toYScale="0.0"

            android:pivotX="50%"

            android:pivotY="50%"

            android:duration="400" />

    </set>

</set>

 

-------------------------------

 

This application code will apply the animation to an ImageView and start the animation:

 

这段应用程序代码将应用动画到一个ImageView并且开始动画:

 

-------------------------------

 

ImageView image = (ImageView) findViewById(R.id.image);

Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);

image.startAnimation(hyperspaceJump);

 

-------------------------------

 

see also:

 

另见

 

* 2D Graphics: Tween Animation

 

* 二维图形:补间动画

 

Interpolators

 

插值器

 

An interpolator is an animation modifier defined in XML that affects the rate of change in an animation. This allows your existing animation effects to be accelerated, decelerated, repeated, bounced, etc.

 

一个插值器是一个定义在XML中的动画修饰符,它影响一个动画改变的速率。它允许让你的现存动画的效果为被加速,被减速,被重复,被反弹,等等。

 

An interpolator is applied to an animation element with the android:interpolator attribute, the value of which is a reference to an interpolator resource.

 

一个插值器被应用到一个带android:interpolator属性的动画元素,其属性值是指向一个插值器资源的引用。

 

All interpolators available in Android are subclasses of the Interpolator class. For each interpolator class, Android includes a public resource you can reference in order to apply the interpolator to an animation using the the android:interpolator attribute. The following table specifies the resource to use for each interpolator:

 

在Android中所有可用的插值器是Interpolator类的子类。对于每个插值器类,Android包含一个公共资源,你可以引用它以应用那个插值器到一个动画,使用android:interpolator属性。以下表格指定用于每个插值器的资源:

 

-------------------------------

 

Interpolator class Resource ID

 

插值器类 资源ID

 

AccelerateDecelerateInterpolator @android:anim/accelerate_decelerate_interpolator

AccelerateInterpolator @android:anim/accelerate_interpolator

AnticipateInterpolator @android:anim/anticipate_interpolator

AnticipateOvershootInterpolator @android:anim/anticipate_overshoot_interpolator

BounceInterpolator @android:anim/bounce_interpolator

CycleInterpolator @android:anim/cycle_interpolator

DecelerateInterpolator @android:anim/decelerate_interpolator

LinearInterpolator @android:anim/linear_interpolator

OvershootInterpolator @android:anim/overshoot_interpolator

 

-------------------------------

 

Here's how you can apply one of these with the android:interpolator attribute:

 

这里是你如何应用这些资源之一到android:interpolator属性上:

 

-------------------------------

 

<set android:interpolator="@android:anim/accelerate_interpolator">

    ...

</set>

 

-------------------------------

 

Custom interpolators

 

自定义插值器

 

If you're not satisfied with the interpolators provided by the platform (listed in the table above), you can create a custom interpolator resource with modified attributes. For example, you can adjust the rate of acceleration for the AnticipateInterpolator, or adjust the number of cycles for the CycleInterpolator. In order to do so, you need to create your own interpolator resource in an XML file.

 

如果你不满足平台提供的插值器(列举在上面的表中),你可以用修改的属性创建一个自定义的插值器资源。例如,你可以调整AnticipateInterpolator的加速速率,或者调整CycleInterpolator的周期数。为了做到这一点,你需要在一个XML文件中创建你自己的插值器资源。

 

* file location:

 

* 文件位置:

 

* res/anim/filename.xml

 

* res/anim/<文件名>.xml

 

* The filename will be used as the resource ID.

 

* 文件名将用作资源ID。

 

* compiled resource datatype:

 

* 被编译的资源数据类型:

 

* Resource pointer to the corresponding interpolator object.

 

* 指向对应插值器对象的资源指针。

 

* resource reference:

 

* 资源引用:

 

* In XML: @[package:]anim/filename

 

* 在XML中:@[<包名>:]anim/<文件名>

 

syntax:

 

语法:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<InterpolatorName xmlns:android="http://schemas.android.com/apk/res/android"

    android:attribute_name="value"

    />

 

-------------------------------

 

If you don't apply any attributes, then your interpolator will function exactly the same as those provided by the platform (listed in the table above).

 

如果你不应用任意属性,那么你的插值器将与那些由平台提供的插值器的功能准确地相同(列举在上面的表中)。

 

elements:

 

元素:

 

Notice that each Interpolator implementation, when defined in XML, begins its name in lowercase.

 

当它被定义在XML中时,注意每个Interpolator的名字以小写开头。

 

* <accelerateDecelerateInterpolator>

 

The rate of change starts and ends slowly but accelerates through the middle.

 

改变的速率缓慢地开始和结束但在通过中间的时候加速。

 

No attributes.

 

没有属性。

 

* <accelerateInterpolator>

 

The rate of change starts out slowly, then accelerates.

 

改变的速率缓慢地开始,然后加速。

 

attributes:

 

属性:

 

* android:factor

 

Float. The acceleration rate (default is 1).

 

浮点型。加速速率(默认为1)。

 

* <anticipateInterpolator>

 

The change starts backward then flings forward.

 

改变开始时向后,然后抛向前。(注:anticipate的意思是抢前,提前)

 

attributes:

 

* android:tension

 

Float. The amount of tension to apply (default is 2).

 

浮点值。应用的张力数(默认为2)。

 

* <anticipateOvershootInterpolator>

 

The change starts backward, flings forward and overshoots the target value, then settles at the final value.

 

改变开始时向后,然后抛向前并且超过目标值,然后移到最终值。

 

attributes:

 

属性:

 

* android:tension

 

Float. The amount of tension to apply (default is 2).

 

浮点值。应用的张力数(默认为2)。

 

* android:extraTension

 

Float. The amount by which to multiply the tension (default is 1.5).

 

浮点性。乘于张力的数量(默认为1.5)。

 

* <bounceInterpolator>

 

The change bounces at the end.

 

改变在最后弹跳

 

No attributes

 

没有属性

 

* <cycleInterpolator>

 

Repeats the animation for a specified number of cycles. The rate of change follows a sinusoidal pattern.

 

以指定周期数来重复动画。改变的速率遵循一个正弦模式。

 

attributes:

 

属性:

 

* android:cycles

 

Integer. The number of cycles (default is 1).

 

整型。周期数(默认为1)。

 

* <decelerateInterpolator>

 

The rate of change starts out quickly, then decelerates.

 

改变的速率开始时很快,然后减速。

 

attributes:

 

属性:

 

* android:factor

 

Float. The deceleration rate (default is 1).

 

浮点型。减速速率(默认为1)。

 

* <linearInterpolator>

 

The rate of change is constant.

 

改变的速率是常量。

 

No attributes.

 

没有属性。

 

* <overshootInterpolator>

 

The change flings forward and overshoots the last value, then comes back.

 

改变抛向前并且超过最后值,然后返回。

 

attributes:

 

属性。

 

* android:tension

 

Float. The amount of tension to apply (default is 2).

 

浮点型。应用的张力数(默认为2)。

 

* example:

 

* 示例:

 

XML file saved at res/anim/my_overshoot_interpolator.xml:

 

XML文件保存在res/anim/my_overshoot_interpolator.xml:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<overshootInterpolator xmlns:android="http://schemas.android.com/apk/res/android"

    android:tension="7.0"

    />

 

-------------------------------

 

This animation XML will apply the interpolator:

 

这个动画XML将应用该插值器:

 

-------------------------------

 

<scale xmlns:android="http://schemas.android.com/apk/res/android"

    android:interpolator="@anim/my_overshoot_interpolator"

    android:fromXScale="1.0"

    android:toXScale="3.0"

    android:fromYScale="1.0"

    android:toYScale="3.0"

    android:pivotX="50%"

    android:pivotY="50%"

    android:duration="700" />

 

-------------------------------

 

Frame animation

 

帧动画

 

An animation defined in XML that shows a sequence of images in order (like a film).

 

一种定义在XML中的动画,它依次显示一连串的图片(像一段电影)

 

* file location:

 

* 文件位置:

 

* res/drawable/filename.xml

 

* res/drawable/<文件名>.xml

 

* The filename will be used as the resource ID.

 

* 文件名将被用作资源ID。

 

* compiled resource datatype:

 

* 被编译的资源数据类型:

 

* Resource pointer to an AnimationDrawable.

 

* 指向一个AnimationDrawable的资源指针。

 

* resource reference:

 

* 资源引用:

 

* In Java: R.drawable.filename

 

* 在Java中:R.drawable.<文件名>

 

* In XML: @[package:]drawable.filename

 

* 在XML中:@[<包名>:]drawable.<文件名>

 

* syntax:

 

* 语法:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"

    android:oneshot=["true" | "false"] >

    <item

        android:drawable="@[package:]drawable/drawable_resource_name"

        android:duration="integer" />

</animation-list>

 

-------------------------------

 

elements:

 

元素:

 

* <animation-list>

 

Required. This must be the root element. Contains one or more <item> elements.

 

必需的。它必须是根元素。包含一个或多个<item>元素。

 

attributes:

 

属性:

 

* android:oneshot

 

Boolean. "true" if you want to perform the animation once; "false" to loop the animation.

 

布尔型。设置为"true"如果你希望执行动画一次;设置为"false"以循环动画。

 

* <item>

 

A single frame of animation. Must be a child of a <animation-list> element.

 

动画的一个单帧。必需是<animation-list>元素的子元素。

 

attributes:

 

属性:

 

* android:drawable

 

Drawable resource. The drawable to use for this frame.

 

可绘画资源。用于此帧的可绘画对象。

 

* android:duration

 

Integer. The duration to show this frame, in milliseconds.

 

整型。显示此帧的持续时间,以毫秒为单位。

 

* example:

 

* 示例:

 

XML file saved at res/anim/rocket.xml:

 

XML文件保存为res/anim/rocket.xml:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"

    android:oneshot="false">

    <item android:drawable="@drawable/rocket_thrust1" android:duration="200" />

    <item android:drawable="@drawable/rocket_thrust2" android:duration="200" />

    <item android:drawable="@drawable/rocket_thrust3" android:duration="200" />

</animation-list>

 

-------------------------------

 

This application code will set the animation as the background for a View, then play the animation:

 

这段应用程序代码将把动画设置为一个View的背景,然后播放动画:

 

-------------------------------

 

ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);

rocketImage.setBackgroundResource(R.drawable.rocket_thrust);

 

rocketAnimation = (AnimationDrawable) rocketImage.getBackground();

rocketAnimation.start();

 

-------------------------------

 

* see also:

 

* 另见:

 

* 2D Graphics: Frame Animation

 

* 二维图形:帧动画

 

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

 

除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。

 

Android 4.0 r1 - 04 Jan 2012 0:53

 

-------------------------------

 

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

 

(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)

 

(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:

* ソフトウェア技術ドキュメントを勝手に翻訳

http://www.techdoctranslator.com/android

* Ley's Blog

http://leybreeze.com/blog/

* 农民伯伯

http://www.cnblogs.com/over140/

* Android中文翻译组

http://androidbox.sinaapp.com/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值