视图动画View Animation入门

View Animation

你可以使用 view animation system 对一个view实现补间动画.

A tween animation can perform a series of simple transformations (position, size, rotation, and transparency) on the contents of a View object.. Theanimation
package
provides all the classes used in a tween animation.

补间动画能够对一个view执行一系列的转置操作,比如位置,大小旋转和移动,animation
package
包提供了所有补间动画的类和方法

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 theAnimationSet
class and other Animation subclasses.)

定义补间动画的一系列指令可以是XML,也可以是Android代码,不过首选XML文件的方式

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 theres/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 thestartOffsetattribute,
as shown in the example below.

animation的xml文件放在 项目的res/anim/目录下,这些文件必须有一个<alpha><scale>,<translate><rotate>,
interpolator element, or <set> 这样的根元素,

切指令是同时执行的,要想顺序执行的话,必须设置startOffset 

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

<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>

屏幕的坐标是左上角的(0,0),然后向下和向右扩展

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.

pivotX:50代表相对于父view,50%相对于自己

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).

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.

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 anImageView object from the layout.

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 withAnimation.setStartTime(),
then assign the animation to the View withView.setAnimation().

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

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.

时间: 2024-12-27 19:26:01

视图动画View Animation入门的相关文章

android 动画 ——视图动画(View Animation)

android动画分为视图动画(View Animation).属性动画(Property Animation) 想看属性动画(Property Animation):请移步至http://blog.csdn.net/u013424496/article/details/51700312 这里我们来说下视图动画(View Animation)的纯代码写法,还有一种是xml调用, 对于xml调用可以去看 http://blog.csdn.net/u013424496/article/details

Android视图动画-View Animation

视图动画主要有两种: 一.Tween Animation译为"补间动画" 1.scale译为"规模.比例",是对View进行特定范围的缩放2.alpha通过改变View的透明度实现View隐现的效果3.translate译为"转移",是对View进行位置的移动4.rotate译为"旋转",是让View围绕特定的点进行旋转PS:所有View的移动.隐藏.旋转仅仅是看到的动画效果,实际View的位置/大小/比例并没有发生本质上的改

*Android动画View Animation

Animations 一.Animations介绍 Animations是一个实现android UI界面动画效果的API,Animations提供了一系列的动画效果,可以进行旋转.缩放.淡入淡出等,这些效果可以应用在绝大多数的控件中. 二.Animations的分类 Animations从总体上可以分为两大类: 1.Tweened Animations:该类Animations提供了旋转.移动.伸展和淡出等效果.Alpha——淡入淡出,Scale——缩放效果,Rotate——旋转,Transl

帧动画Drawable Animation入门

Drawable Animation Drawable animation lets you load a series of Drawable resources one after another to create an animation. This is a traditional animation in the sense that it is created with a sequence of different images, played in order, like a

Android四大视图动画图文详解

Android中的动画分为视图动画(View Animation).属性动画(Property Animation)以及Drawable动画. Android从最初的版本就支持视图动画,视图动画顾名思义,就是应用在视图View上的动画.视图动画的核心类是android/view/animation/Animation,该类是一个抽象类,该类有五个子类,分别是AlphaAnimation.TranslateAnimation.RotateAnimation.ScaleAnimation.Anima

Android动画之视图动画和属性动画

Android 动画分为两大类,分别是视图动画(View Animation)和属性动画(Property Animation).对于这两种动画,都能够使用xml和代码的形式定义动画. 注:布局动画相关博客已经发布,有兴趣可跳转Android动画之布局动画 View Animation 视图动画是Android最基础的动画,在API 1中就已经加入,不需考虑兼容性,但由于其动画只是作用于视图上,而不会由该控件的属性,所以有很多的局限性. 视图动画的基类是Animation其下包含了四个直接的子类

Android动画三部曲之一 View Animation &amp; LayoutAnimation

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/50612827 本篇文章对android的Tween动画和帧动画以及布局动画进行总结. Tween动画 XML语法介绍 插值器 Interpolator 自定义Interpolator 公共XML属性及对应的方法 ScaleAnimation 缩放动画 xml定义缩放动画 代码定义缩放动画 RotateAnimation 旋转动画 xml中设置旋转动画 代码中设置旋转动画 Transl

【Android 动画】View Animation详解(一)

安卓平台目前提供了两大类动画,在Android 3.0之前,一大类是View Animation,包括Tween animation(补间动画),Frame animation(帧动画),在android3.0中又引入了一个新的动画系统:property animation,即属性动画.本篇文章主要介绍View Animation的基本使用方法与技巧,属性动画将在下一篇博文中介绍. Tween动画可以执行一系列简单变换(位置,大小,旋转,缩放和透明度).所以,如果你有一个TextView对象,您

Android动画之二:View Animation

作为一个博客<Android其中的动画:Drawable Animation>.android动画主要分为三大部分.上一篇博客已经解说Drawable Animation的使用方法,即逐帧地显示图片,常常运用于动态显示一个进度动画,这是出现频率最高的应用场景.接下来.我们这篇文章将循序渐进.介绍View Animation. View Animation也是我们平时非常多书籍所说的Tweened Animation(有人翻译为补间动画).View Animation分为4大类:AlphaAni