Property animation-Overview and working principles

Source: Internet
Author: User

Overview
In Android, the property animation system is a robust framework that allows you to make everything move. You can define an animation to change the attribute value of any object over time, regardless of whether it is drawn on the screen. An Attribute animation can change the value of an attribute within a specified period of time. To make things work, you need to specify the attributes of an object (for example, the position of an object on the screen ), how long do you want it to exercise and what value range do you want it to exercise. In the android property animation system, we can define the following features for an animation:
Duration: You can specify the duration for an animation. The default duration is 300 ms.
Time interpolation: You can specify the attribute value based on the current animation running time.
Number of repetitions and behavior: You can specify the number of repetitions after an animation is completed. You can also specify the reverse motion of the animation, and the number of repetitions ends.
Animation set: You can make some animations into a logical set, moving together, in sequence, or after a specified delay.
Frame Rate: You can specify an animation frame rate. The default value is one frame every 10 ms. However, in your application, the frame rate of animation playback depends on the overall system busy and the timer service at the bottom of the system.
The working principle of property animation first let's look at a simple example animation. Figure 1 depicts a hypothetical object that uses X property motion, the X property represents its position on the screen in the water direction. The animation duration of this X attribute is 40 ms, and the distance to be completed is 40 pixels. The refresh frequency of each frame is 10 ms, and each switching frame moves 10 pixels. After 40 ms, the animation stops, and the moving object is 40 pixels horizontally. This is a linear interpolation animation, which means that the object moves at a constant speed. Figure 1. Example
Of a linear animation in the android property animation system, you can also specify an animation that is not linear interpolation. Figure 2 illustrates a hypothetical object, where the first half is accelerated and the second half is slowed down. But it still uses 40 ms to move 40 pixels, which is obviously not linear. Moving at the beginning and end is slow, but moving at the center is fast.

Figure 2. Example of a non-linear Animation

Now let's take a closer look at the important components of the android property animation system's animation computing system. Figure 3 describes the relationships between main classes

Figure 3. How animations are calculated

Valueanimator tracks the animation process, for example, how long the animation has been played, and the value of each attribute at a time point. Valueanimator encapsulates TimeInterpolator, TimeInterpolatorThe animation interpolation is defined and a typeevaluator is encapsulated. The typeevaluator defines how to calculate attribute values during animation playback. For example, in Figure 2, timeinterpolator may use AccelerateDecelerateInterpolatorTypeevaluator may use intevaluator to start an animation. You need to create a valueanimator and set the start and end values and animation duration for the attributes you want to exercise. When you call start()The animation starts. During the animation process, ValueAnimatorA completed score is calculated in real time. The value ranges from 0 to 1. This calculation depends on the animation duration and the time when the animation has been moved. The completed score indicates how long the animation takes. For example, in figure 1 (note the constant speed), the score is 0.25 at t = 10 ms, because the duration is t = 40 ms when ValueAnimatorAfter the score is calculated, the currently set TimeInterpolatorTo calculate an interpolation score. An Interpolation score maps the completed score to a new score under fully-considered time interpolation. For example, in figure 2 (non-uniform speed), because the animation is slowly accelerating, at t = 10 ms, the interpolation score is 0.15 (6/40), less than the completion score of 0.25. In Figure 1, the interpolation scores and the completion scores are always equal. After the interpolation score is calculated, valueanimator calls an appropriate typeevaluator to calculate the attribute value. Based on the interpolation score, the start value and the animation end value. For example, in Figure 2, the interpolation score at t = 10 ms is 0.15, so the attribute value at t = 10 ms is
0 (startpos) + 0.15 * (40-0) = 6 in the API
Demos, com.example.android.apis.animationThe package introduces how to use the property animation System of Android. The difference between attribute animation and view animation the view animation system only provides us with the view animation capability. Therefore, if you want to animation non-view objects, you only need to write your own code. View animation is limited to some actual situations. Only some aspects of the view can be used for animation, such as scaling and rotation, but the background color is not good. Another disadvantage of view animation is that only a view drawn on the screen can be animated, and it is not the view itself. For example, if you want a button to move on the screen, after the button is moved, it can be drawn on the correct coordinates, however, the actual place you can click on the screen (before moving) does not change, so you need to implement your own logic to handle this situation. In the Property animation system, these restrictions do not exist at all. You can animation any attributes of any object and the object itself will be modified. Property animation can be performed in a more robust way. In a higher version, you can specify the animation for the attributes you want to modify, such as color, position, or size, in addition, it can define several aspects of the animation at the same time, such as interpolation and synchronization of multiple animations, but the view animation system also has some advantages, for example, you can set and write less code in less time. If view animation can do anything you want, or if your existing code already works as you want, there is no need to use the property animation system. Sometimes it makes sense to use two types of animation systems at the same time.

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.