Android animation from the source angle analysis of the animation principle

Source: Internet
Author: User

I've never understood the animation mechanism of Android, how the Android system is animated, so it will only do some of the animations that the Android system has packaged for us: Alphaanimation, Translateanimation, Scaleanimation,rotateanimation and these animations are mixed together, there are actually Android systems for us to provide these kinds of animation is to meet our usual basic needs, but to do some advanced animation is impossible, such as 3D animation, So I looked at the Android system led by the source of the painting, did some summary, the following is my new understanding of the animation.
1. The most important class, the animation class, an abstract class, is the base class for all animations, which defines the public properties and methods of animation, the most important of which are: Animationlistener and transformation, animation listeners, Listen to the beginning of the animation, the execution process, the end, you can implement some of their own logic, transformation is the information contained in each frame animation (translation, rotation, bloom, transparency) The most important method is:

public boolean gettransformation (long currenttime, Transformation outtransformation), and protected void Applytransformation (float interpolatedtime, transformation t).
The first method is called by the system, based on the current time of the animation to calculate the transformation information at this time, do not have to override this method, the second method is we have to rewrite, according to the system by the first method calculated by the transformation for the actual animation implementation.
2. From the animation class above, you can know the most important attributes and the most important method, both have a class called transformation, it is also important to see this class, The most important attributes that can be seen in the Tranfrormation class are alphat and matrix, where alpha is the transparency information that really holds the animation, and the matrix is the information that holds (pan, rotate, bloom). This shows that these two are really the carrier of all the information that holds a frame of animation.
The most important method is Getmatrix (). Gets all the animation information in the existing matrix in the current frame animation.
3. The 2nd is that, in addition to the transparency information, the frame information of the animation is stored in the matrix class, so we also need to understand how the matrix works. In the Matrix class, we can see that there is a series of setxxx,prexxx,postxxx methods in this class, that is, the setting of the three series to Rotate,scale,translate. Check out some of the online articles, probably understand the difference between the three methods. The Prexxx method is to make a right multiplication of the original matrix, that is, m*a (the future M represents the original matrix), Postxxx represents the left multiplication of the original matrix, that is B*m, the setxxx represents the original matrix data first emptied, then the right multiplication. The difference between the left and right multiplication is that when the matrix is multiplied, the right multiplication is performed, and then the right multiplication is executed, then the left multiplication is performed, and the effect of the animation is superimposed on the effect data of the right multiplicative matrix, and then the effect data of the left multiplicative matrix is superimposed. The effect of the left and right multiply is completely different. The concrete matrix operation says this article, said very well. Android matrix theory and application. The matrix is handled by the Android system, and all the programmers have to do is pass the offset into the corresponding method.
4.android system for us to provide the animation is the most basic, two-dimensional, so all the 3D animation we have to implement, And Android gives us the camera class under the Graphic.camera package, which is the class that implements the 3D effect, and my understanding of this class is that the Android system provides a pair of eyes for our program. This is the camera, our human eyes can be observed from the XYZ three axis, the camera is also possible, through the camera class on different axes of movement, but also can achieve the animation effect, from the camera class code can see its several methods: public native void translate (float x, float y, float z) and public native void rotate (float x, float y, float z), public void Getmatr IX (Matrix matrix). These three methods, the first one is to move the camera on XYZ three axes, the camera moves to the left, you can achieve the right translation animation effect. Other panning effects are the same. The second method is the rotation on the XYZ axis, which can achieve stereoscopic animation by rotating on these three axes, and the third method is to overlay all operations on the camera into the Matric object.
After we understand the functions of the above four classes, we basically understand the animation principle of Android, by inheriting the base class: Aniomation and rewriting applytransformation, and using Matrix,camera to implement some effects, that is, animation.
Below, we use the camera to achieve the general rotation animation and 3D rotation animation, as well as using camear to achieve our commonly used zoom animation.
1) Pan animation with camera.

Detailed Description: http://android.662p.com/thread-6081-1-1.html

Android animation from the source angle analysis of the animation principle

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.