`

【翻译】(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/


分享到:
评论

相关推荐

    Android进阶-Android动画机制与使用技巧

    视图动画主要包括翻译(Translate)、旋转(Rotate)、缩放(Scale)和透明度变化(Alpha)。使用`Animation`类及其子类可以创建这些基本动画,通过`setDuration()`设置动画时长,`start()`启动动画。此外,`...

    android动画图标

    视图动画主要包括翻译(Translation)、旋转(Rotation)、缩放(Scale)和透明度(Alpha)这四种基本变换。开发者可以使用`Animation`类或XML资源文件定义动画,然后通过`startAnimation()`方法应用到视图上。例如...

    android 动画demo

    视图动画主要包括翻译(Translation)、旋转(Rotation)、缩放(Scale)和透明度变化(Alpha)四大类。这些动画可以通过AnimationSet组合在一起,形成复杂的动画序列。例如,一个简单的按钮点击动画可能包含按钮平...

    Launcher滑屏动画详解

    8. **矩阵应用**:在绘制过程中,我们需要先取消滚动翻译,然后应用`Transformation`的矩阵,最后重新应用滚动翻译,以确保动画的正确显示。 9. **自定义动画**:开发者可以通过覆写`drawChild`方法,结合`...

    ios核心动画高级技巧.

    - 在iOS开发中,视图(UIView)通常与图层(CALayer)紧密相关,UIView负责处理触摸事件和用户交互,而CALayer负责视图的显示内容和动画。 - CALayer类似于UIView的容器,它也可以包含内容并管理子图层的位置。 -...

    iOS 词典手势和视图

    在iOS中,UIView类是最基础的视图类型,它提供了绘制、动画和事件处理的能力。例如,在词典应用中,我们可以创建一个UIView实例来展示单词的解释或者例句。通过自定义视图,我们可以设计独特的布局和视觉效果,以...

    iOS核心动画高级技巧

    以上知识点涵盖了《iOS核心动画高级技巧》一书中关于Core Animation的大部分核心概念和高级技巧,涉及动画的基础知识、图层树的结构、视图与图层的关系、自定义绘图、动画实现方法、性能优化以及如何利用专业图层类...

    iOS 7学习:View Controllers之间的切换动画对应的Demo

    这个Demo是专门针对iOS 7中的视图控制器转换动画进行实践的。下面我们将详细讨论这些知识点: 1. **UIStoryboardSegue**: UIStoryboardSegue是苹果为实现不同视图控制器之间过渡而提供的类。它定义了在两个视图...

    unity 界面菜单翻译

    9. ** Animator**:处理角色动画和控制器,是制作游戏动画的关键部分。 10. **Asset Store**:Unity内置的市场,提供免费和付费的插件、素材和教程,方便开发者扩展功能。 Unity界面的中文翻译将这些关键元素和...

    Android实例Animation

    视图动画包括动画集(AnimationSet)、翻译动画(TranslateAnimation)、旋转动画(RotateAnimation)、缩放动画(ScaleAnimation)和淡入淡出动画(AlphaAnimation)。这些动画可以通过XML文件定义,也可以在代码中...

    WPF实例程序,命令,动画,资源,本地化等等

    WPF提供了强大的本地化支持,可以方便地将应用翻译成不同语言。使用`Resx`文件管理字符串资源,然后通过`ResourceManager`和`CultureInfo`加载相应的资源,实现应用程序的语言切换。 6. **拖放(Drag and Drop)** ...

    核心动画、多线程编程、blocks编程要点、pdf 文件绝对能帮到你

    它主要处理视图的渲染,提供了低级别的动画控制,让开发者可以创建出平滑、连续的视觉效果。以下是一些Core Animation的关键知识点: - **CALayer**: 是Core Animation的基础,负责绘制和管理屏幕上的内容。每个...

    iOS Core Animation 中文翻译版

    隐式动画是当视图的属性发生变化时,系统自动执行的动画效果;而显式动画则是程序员通过代码显式指定的动画。开发者可以通过Core Animation框架提供的方法来控制动画的起止、速度、缓动等,实现个性化的动画效果。 ...

    3DMAX英文翻译及快捷键操作

    菜单栏主要包括File(文件)、Edit(编辑)、Tools(工具)、Group(群组)、Views(查看)、Create(创建)、Modifiers(修改)、Character(角色)、Animation(动画)、Graph Editor(图形编辑)、Rendering...

    android 风车效果

    视图动画则主要适用于API level 10及以下版本,通常包括翻译、旋转、缩放和淡入淡出等效果。 在“android 风车效果”这个场景中,我们可能需要使用属性动画来实现风车叶片的旋转,因为这能让我们更好地模拟手拨动后...

    Android 字体抖动效果Demo

    属性动画系统是在Android 3.0(API级别11)引入的,它可以对对象的任意属性进行动画处理,而视图动画则是早期版本中的系统,它实际上只是改变视图的显示状态,并非真正的对象动画。 在本Demo中,我们可能会用到属性...

    带有修剪文本的自定义文本视图

    考虑到应用可能需要支持多种语言,自定义TextView需要确保“阅读更多”这样的短语能够被正确地翻译和显示。 10. **性能优化** 自定义组件需要考虑性能问题,避免不必要的计算和内存消耗。例如,可以缓存修剪前后...

    基于Android手语动画软件设计.pdf

    基于Android平台的手语动画软件正是为了促进聋哑人与正常人之间的沟通交流而设计的,它集成了多项先进的技术,为用户提供了翻译和学习手语的便利途径。 Android平台的开放性为应用软件的开发提供了广阔的环境,使得...

    ios-高仿Uber启动动画.zip

    这是根据Raywenderlich上How to create an Uber splash screen这篇文章实现的高仿Uber动画效果。你可以在这里找到相应的中文翻译:...

Global site tag (gtag.js) - Google Analytics