`

【翻译】(76)视图动画

 
阅读更多

【翻译】(76)视图动画

 

see

http://developer.android.com/guide/topics/graphics/view-animation.html

 

原文见

http://developer.android.com/guide/topics/graphics/view-animation.html

 

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

 

View Animation

 

视图动画

 

You can use the view animation system to perform tweened animation on Views. Tween animation calculates the animation with information such as the start point, end point, size, rotation, and other common aspects of an animation.

 

你可以使用视图动画系统以执行View上的补间动画。补间动画使用一些信息诸如开始点、结束点、大小、旋转和一个动画的其它一般方面来计算动画。

 

A tween animation can perform a series of simple transformations (position, size, rotation, and transparency) on the contents of a View object. So, if you have a TextView object, you can move, rotate, grow, or shrink the text. If it has a background image, the background image will be transformed along with the text. The animation package provides all the classes used in a tween animation.

 

一个补间动画可以在一个View对象的内容上执行一系列简单变换(位置,大小,旋转,和透明度)。所以,如果你拥有一个TextView对象,你可以移动,旋转,增高,或缩短该文本。如果它拥有一个背景图片,背景图片将伴随文本而被变换。animation包提供在一个补间动画中使用的所有类。

 

A sequence of animation instructions defines the tween animation, defined by either XML or Android code. As with defining a layout, an XML file is recommended because it's more readable, reusable, and swappable than hard-coding the animation. In the example below, we use XML. (To learn more about defining an animation in your application code, instead of XML, refer to the AnimationSet class and other Animation subclasses.)

 

一个动画指令序列定义补间动画,通过XML或Android代码来定义。正如定义一个布局所用的,建议使用一个XML文件,因为它必手工编码动画更可读,可重用,以及可交换。在下面的示例中,我们使用XML。(要想知道关于在你的应用程序代码中定义一个动画的更多信息,而非使用XML,请参考AnimationSet类以及其它Animation子类。)

 

The animation instructions define the transformations that you want to occur, when they will occur, and how long they should take to apply. Transformations can be sequential or simultaneous - for example, you can have the contents of a TextView move from left to right, and then rotate 180 degrees, or you can have the text move and rotate simultaneously. Each transformation takes a set of parameters specific for that transformation (starting size and ending size for size change, starting angle and ending angle for rotation, and so on), and also a set of common parameters (for instance, start time and duration). To make several transformations happen simultaneously, give them the same start time; to make them sequential, calculate the start time plus the duration of the preceding transformation.

 

动画指定定义你希望发生的变换,当它们将发生时,以及它们将花多长时间应用。变换可以是串行或并行的——例如,你可以让一个TextView的内容从左移动到右,然后旋转180度,或者你可以让文本同时移动并旋转。每个变换持有特定用于那个变换的一组参数(开始大小和结束大小用于大小改变,开始角度和结束角度用于旋转,等等),还有一组通用参数(例如,开始时间和持续时间)。为了让几个变换同时发生,给它们相同的开始时间;为了令它们依次发生,计算开始时间加上前一个变换的持续时间。

 

The animation XML file belongs in the res/anim/ directory of your Android project. The file must have a single root element: this will be either a single <alpha>, <scale>, <translate>, <rotate>, interpolator element, or <set> element that holds groups of these elements (which may include another <set>). By default, all animation instructions are applied simultaneously. To make them occur sequentially, you must specify the startOffset attribute, as shown in the example below.

 

动画XML文件归入你的Android工程的res/anim/目录。文件必须拥有一个根元素:它将是其中一个单一的<alpha>,<scale>,<translate>,<rotate>,插值器元素,或持有这些元素分组的<set>元素(它可以包含另一个<set>)。默认,所有动画指定被同时应用。为了让它们依次地发生,你必须指定startOffset属性,正如下面的示例中所示。

 

The following XML from one of the ApiDemos is used to stretch, then simultaneously spin and rotate a View object.

 

以下出自其中一个API演示的XML被用于拉伸,然后同时拉长(注:spin也有旋转的意思)并旋转一个View对象。

 

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

 

<set 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/decelerate_interpolator">

        <scale

           android:fromXScale="1.4"

           android:toXScale="0.0"

           android:fromYScale="0.6"

           android:toYScale="0.0"

           android:pivotX="50%"

           android:pivotY="50%"

           android:startOffset="700"

           android:duration="400"

           android:fillBefore="false" />

        <rotate

           android:fromDegrees="0"

           android:toDegrees="-45"

           android:toYScale="0.0"

           android:pivotX="50%"

           android:pivotY="50%"

           android:startOffset="700"

           android:duration="400" />

    </set>

</set>

 

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

 

Screen coordinates (not used in this example) are (0,0) at the upper left hand corner, and increase as you go down and to the right.

 

屏幕坐标(在这个示例中未使用)是在左上角的(0, 0),并且随着你向下走(注:待考)而增加并向右。

 

Some values, such as pivotX, can be specified relative to the object itself or relative to the parent. Be sure to use the proper format for what you want ("50" for 50% relative to the parent, or "50%" for 50% relative to itself).

 

一些值,诸如pivotX,可以相对于对象自身或相对于父对象来指定。确保使用正确的格式用于你想要的东西("50"表示相对于父对象的50%,或者"50%"表示相对于它自身的50%)。

 

You can determine how a transformation is applied over time by assigning an Interpolator. Android includes several Interpolator subclasses that specify various speed curves: for instance, AccelerateInterpolator tells a transformation to start slow and speed up. Each one has an attribute value that can be applied in the XML.

 

你可以通过赋予一个Interpolator来决定一个变换如何随时间过去而被应用。Android包含几个Interpolator子类,它们指定不同速度的曲线:例如,AccelerateInterpolator告诉变换缓慢开始然后加速。每个(注:每个插值器?)拥有可以在XML中应用的一个属性值。

 

With this XML saved as hyperspace_jump.xml in the res/anim/ directory of the project, the following code will reference it and apply it to an ImageView object from the layout.

 

带有在工程的res/anim/目录中保存为hyperspace_jump.xml的XML,以下代码将引用它并应用它到来自布局的一个ImageView对象。

 

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

 

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

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

spaceshipImage.startAnimation(hyperspaceJumpAnimation);

 

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

 

As an alternative to startAnimation(), you can define a starting time for the animation with Animation.setStartTime(), then assign the animation to the View with View.setAnimation().

 

作为对startAnimation()的一个替换方案,你可以用Animation.setStartTime()为动画定义一个开始时间,然后用View.setAnimation()赋予动画给该View。

 

For more information on the XML syntax, available tags and attributes, see Animation Resources.

 

想获得关于XML语法,可用的标签以及属性的更多信息,参见动画资源。

 

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

 

Note: Regardless of how your animation may move or resize, the bounds of the View that holds your animation will not automatically adjust to accommodate it. Even so, the animation will still be drawn beyond the bounds of its View and will not be clipped. However, clipping will occur if the animation exceeds the bounds of the parent View.

 

注意:不管你的动画可以如何移动或改变大小,持有你的动画的View的范围将不会自动地调整以适应它。虽然如此,动画将仍然超出它的视图的范围而被绘画并且将不被剪裁。然而剪裁将发生,如果动画超出父View的范围。

 

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

 

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 - 08 Mar 2012 0:34

 

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

 

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/


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics