[Android Animation] Brief Analysis of Animator, Animation, and androidanimator
If you like my blog, please pay attention to my Weibo, please click here (http://weibo.com/kifile), thank you
Reprinted please indicate the source (http://blog.csdn.net/kifile), thank you again
During Android development, we usually use more or less animations. Generally, we use Animation, but in fact, Android 3.0 has launched the Animator framework to improve the animation effect of Android. Although we generally cannot enjoy the Animator service during development based on 2.x, however, this does not affect us to try out his strength.
First, let's take a look at Animation. The support of the Animation framework is much earlier than that of Animator. It has existed since the date of Android release. It mainly has the following sub-classes: AlphaAnimation (transparency ), rotateAnimation (rotation), ScaleAnimation (scaling), TranslateAniamtion (translation), and AnimationSet (animation set)
From the name, we can clearly know that animation types supported by Aniamtion are few. They are nothing more than transparent, rotation, scaling, and translation subsets.
Compared with Aniamtion, Animator is more powerful. It can not only perform animations for views, but even "Animation" operations on all objects, in addition, the Animation effect after the Animation or is used is completely different from the Animation effect after the Animation or is used.
There are actually many similar interfaces between an Animation and an Animation, such as duration and interceptor, which are used to determine the specific implementation duration and difference device of the Animation. For this, we don't need to introduce it too much.
Let's take a look at the implementation principles of the Animation and Animation:
(1) For animations:
Its implementation mechanism is to transform the matrix of the entire canvas each time a drawing is performed to realize the movement of View coordinates, however, the actual coordinates and other related attributes within the View are always constant.
(2) For animations:
The implementation mechanism of the animation is actually simpler, because it is only the value that a certain attribute should have at a certain time point before the animation is started, then, you can set the specific value through the callback interface. In fact, the animation is not refreshed for a view internally in the Animator to implement the animation. When you set the specific value, this method is implemented by self-tuning methods such as invalidate. that is to say, the internal attributes are changed when Animator is used.
Now let's talk about their basic implementation principles.Compare their strengths and weaknesses:
(1) version compatibility
I have to say that, compared with Animation, the version compatibility of Animator is still too poor. It is not available until Android3.0, and it cannot meet the compatibility support of the current development environment 2.x, in addition, the android official support package does not support earlier versions of Animator. Therefore, the version compatibility alone is not enough. However, this is a historical reason for the system and we can only accept it.
(2) Efficiency
Similarly, this is also a disadvantage of Animator. Because Animator directly sets the setter and getter methods of the object to play the animation display effect, in order to call the correct method for any object, animator uses a Java reflection mechanism, while Animation directly processes the matrix through code. Therefore, in terms of efficiency, Animator is inferior to Animation.
I have already mentioned the two disadvantages of Animator compared with Animation. Let's talk about it again.Advantages of Animator over Animation
(3) Applicability
In the previous analysis, we can see that the efficiency of Animator is low due to the reflection mechanism, but this also increases the scope of its applicable objects, animation is only useful for a View object. However, Animator can set attributes of any object so that it can be changed within a certain period of time.
(4) Effects
I believe that when you use Animation, you may find that when the Animation is being moved or the Animation is completed, but the position changes, you click the previous position and the click effect still exists, this is because the internal Coordinate Position of the View has not actually changed. If you use Animator for displacement transformation, your click position will change accordingly with the animation effect, so even if you are in the animation process, you can click the button to get the desired effect.
The above four points are the strengths and weaknesses of Animation and Animator, and hope to be useful to you.
In Unity3D43, the Animation system was changed to Animator. In the past, where was the Play automatically automatic keys of Animation?
Animator has a state machine to control the playback of animation frames.
For example, the setTrigger method is available.
We recommend that you read the official documentation.
There is a default state on the animator interface. You can create an empty state and set the empty state to the default state.
Android Animation: translateanimation. Can two widgets smoothly execute the same animation?
Yes, you can use an animation to write an internal file separately ?? Method, and the view parameter control is passed in to use the thread for Synchronous playback. Of course, the upstairs said yes. It is a global influence, not the influence of every component.