Android Animation specifically explains the principle of two-attribute animation

Source: Internet
Author: User

Property animation is a powerful framework that can almost make you animate whatever it is.

You can define an animation to change the object's properties regardless of whether it is drawn on the screen or not.

A property animation changes the value of an attribute (a field of an object) several times within a certain amount of time. To animate something. You need to specify the object's target properties. For example, position, duration of the animation. and change the range of values.

The property animation system agrees that you specify the following animation properties:

· Duration: The duration of the animation.

The default is.

· Time interpolation: You can specify a function to define how to calculate the value of a property in the current timeframe.

· Recurrence and behavior: You can specify whether to start again at the end of the animation and repeat the number of times. You can still specify whether to let the animation play backwards. Set the animation to play backwards so that the animation is broadcast first and then backward again. Until the limit of repeated times is reached.

· Animation set: You can logically place multiple animations in a group to play together or play back in sequence or at a specified delay time.

· Frame Refresh delay: You can specify the animation's frame refresh rate. The default is set to ten Ms. However, the actual speed at which your app can refresh the frame finally depends on how busy the system is and how quickly the system executes the backend code.

· How Property animations work

First, let's take a sample to get a general idea of how an animation works. Description describes an object to animate its x attribute. This stands for its transverse position. The animation duration is set to MS and its animation distance is set to 40 pixels. Moves 10 pixels per Ms. After 40ms, the animation stops. The object is parked in a position of 40.

This is an object that uses linear interpolation to indicate that the object is moving at a constant speed.


Figure 1. Examples of linear animations

You can also use non-linear interpolation animations. Demonstrates an animation that starts accelerating and slows down at last. The object still moves 40 pixels in 40 seconds, but it is non-linear.

Start accelerating to the halfway and slowing down until the end. As you can see. The distance moved at the beginning and end is shorter than the distance moving in the middle.



Figure 2. Examples of nonlinear animations

Let's take a closer look at how the property animation system calculates the important parts of the animation that we see.

Demonstrates how the main classes interoperate with each other.


Figure 3. How the animation is calculated

The valueanimator object keeps track of the animation time, for example, how long the animation has been executed, and the current value of the property.

The valueanimator encapsulates a timeinterpolator, which defines an animation interpolation algorithm and encapsulates a typeevaluatorthat defines how to calculate the value of a property. For example, in Figure 2, the timeinterpolator used is acceleratedecelerateinterpolator and the typeevaluator used is Intevaluator.

To start an animation, you create a valueanimator and then tell it the start and end values of the properties to animate, and the duration of the animation. When you call start () , the animation starts. During the animation. valueanimator with the duration of the animation and the time that has gone, calculates a fraction (between 0 and 1) that represents the scale of the progress, the progress score represents the percentage of time the animation has been made, and 0 represents 0%,1 100%.

For example, the progress score in Figure 1 is at t = Ten ms when the value is. 25, because the total time is T = Ms.

When Valueanimator calculates a progress score, it calls timeinterpolator to calculate an interpolation score. The insertion fraction maps the progress score to a new score by combining the time interpolation set. Like what. In Figure 2, the animation slowly accelerates, at t = Ten Ms. The interpolation score is. 15, less than the progress score of. 25. In Figure 1, the interpolation score progress score is always equal.

When the interpolation function is computed. Valueanimator calls the appropriate Typeevaluator to calculate the value of the property you are animating based on the interpolation function, start value, and end value.

For example, in Figure 2 , the value of the interpolation function is. 15 when t = Ten Ms. So some time the value of the property will be. X (40-0). or 6.


Previous: Android animation specific explanation of an overview

Next: Android Animation specific explanation three animation API overview

Android very often to use the NDK development, for C language is not very familiar with the small partner, can look at my recorded video tutorial: http://edu.csdn.net/course/detail/2057

I hope you have some help!


Android Animation specifically explains the principle of two-attribute animation

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.