Android Animation Learning (a) Property animation introduction

Source: Internet
Author: User

Android Animation

The Android framework provides two animation systems: Property Animation (introduced in Android 3.0) and view animation.

In addition to these two systems, you can also take advantage of drawable animation, which is the playback sequence frame image.

So, there are three types of animation in Android:

1. Property Animation

2. View Animation

3. drawable Animation

The following is mainly about property Animation.

Property Animation

  The property Animation is the introduction of Android 3.0 , also known as APIlevel, which allows you to set any object Animate any property (even if it is not on the screen) .

To make something move, you specify the properties to be transformed by the object, the duration of the animation, and the value you want to achieve in the animation.

  With the property animation system you can define the following characteristics of an animation:

  Duration: The duration of the animation, the default value is 300ms.

  Time interpolation: Temporal interpolation, you can define how the value of a property is transformed over time.

  Repeat count and behavior: You can specify whether an animation is repeated and repeated several times, or whether you want the animation to rewind backwards so that the animation can go back and forth until the required number of repetitions is reached.

  Animator Sets: You can organize animation behavior into a logical collection that plays together or sequentially, or can be played after a specified delay.

  Frame Refresh delay: You can specify how often you will refresh the frame of your animation. The default value is set to every 10ms, but your app's refresh frame frequency is related to the current reality of the system.

Introduction to how the property Animation works

  ValueAnimator The object holds the animation time, such as how long the animation has been, and the current value of the transformed property.

timeinterpolator and typeevaluatorare encapsulated in the valueanimator .

Timeinterpolator defines the time interpolation of the animation, such as linear or accelerated deceleration;

Typeevaluator defines how to calculate the property values that are changed by the animation.

  

To start an animation, first construct a valueanimator object, tell it the starting value, the ending value, and the animation time of the property value you want to change, and when you call the start() method, the animation begins.

  Throughout the animation process, the calculations involved are divided into three steps:

1. The valueanimator Object calculates a elapsed fraction value between 0 and 1 based on the total time of the animation and the elapsed time. This elapsed fraction value represents the degree to which time is completed.

2. After calculating the elapsed fraction , thevalueanimator object is called TimeInterpolator to calculate a interpolated fraction, i.e. , the elapsed fraction is mapped to the interpolated fractionbased on the time interpolation method you set.

For linear interpolation , elapsed fraction and interpolated fraction are always equal, but nonlinear transformations are not.

3. interpolated fraction is computed, it ValueAnimator is called to TypeEvaluator perform the calculation of the property values you want to animate.

The input parameter used at this time is the value of the interpolated fraction , as well as the starting and ending values of the property values .

The entire process is as follows:

Property Animation API

Most APIs for the property animation system are in this package:android.animation

But since the view animation system defines some interpolator (interpolator), you can use some of the interpolator in this package android.view.animation directly.

  

Link: http://developer.android.com/guide/topics/graphics/prop-animation.html in the API Overview Section list describes the property Animation API, you can go to view.

The API is mainly divided into table 1. animators, Table 2. evaluators, Table 3. interpolators three parts.

  In Animatiors:

Valueanimator only calculates the attribute value, does not set the property value on the object, so you must listen to the update of the property value, modify the object's properties, and implement the animation logic.

Usage See:animating with Valueanimator

Objectanimator is a subclass of Valueanimator , where the name of the target object and the corresponding attribute value is passed in the constructor (requiring the object class to have a corresponding Get/set method), the property is automatically set to be worthwhile.

Usage See:animating with Objectanimator

Animatorset provides a combination of animation,

Usage See: choreographing multiple animations with Animator sets

  

In addition, Animation Listeners is also important:Animation Listeners

the relationship between property animation and view animation

  View Animation is an older set of systems that only works with view objects.

And the View animation system limits the aspects that can be animated, such as scaling and rotation, but the background color animation is not possible.

  Another drawback of the view animation system is that it only changes the location of the view drawing and does not change the actual location of the view itself.

For example, if you have a button that moves through an animation to another location on the screen, although it is drawn at the target location, but you want to click it or you want to be in the original position, you need to write your own logic to deal with the problem.

The property animation system does not have the above problem, it does change the real properties of the View object .

  

  From Android 3.0, the view class adds many properties and methods for property animation.

These properties are:

Translationx and Translationyrotation, RotationX, and Rotationyscalex and Scaleypivotx and Pivotyx and Yalpha

When these property values are changed, theview automatically calls the invalidate() method to refresh.

declaring animations in XML

The property animation system allows you to use XML to declare animations, one that can be used for animation reuse, more versatility, and another benefit is that editing sequences of multiple animations is easier and more readable.

To differentiate between the property animation and the View animation resource file, the property animation XML file exists from the Android 3.1 res/ under the animator/directory (View animation exists res/anim/ directory), animator this name is optional. But if you want to use the layout editor of Eclipse ADT Plugin (ADT 11.0.0+), you must use the res/animator/directory, because ADT is only looking for the property in that directory animation resource file.

The corresponding labels are as follows:

    • ValueAnimator-<animator>
    • ObjectAnimator-<objectAnimator>
    • AnimatorSet-<set>

define the semantics of the property Animation, see: Animation Resources

References

Official API Guides:

Http://developer.android.com/guide/topics/graphics/overview.html

Property Animation:

Http://developer.android.com/guide/topics/graphics/prop-animation.html

Property Animation Package:

Http://developer.android.com/reference/android/animation/package-summary.html

Android Animation Learning (a) Property animation introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.