Android realizes 3D flip animation effect

Android does not provide direct 3D flip animation, so we need to realize the animation effect of 3D flip by ourselves. Let's first analyze animation and transformation.

Animation is the main interface of animation, which mainly defines some attributes of animation, such as start time, duration, whether to play repeatedly, etc. Transformation contains a matrix and alpha value. The matrix is used for translation, rotation and scaling animation, and the alpha value is used for alpha animation. To realize 3D rotation animation, we need to inherit from the animation class. We need to overload gettransformation and applytransformation, In gettransformation, animation will generate a series of difference points according to the animation properties, and then pass these difference points to applytransformation. This function will generate different transformations according to these points. Here is

Specific implementation:

It includes the start and end angles of rotation, the center point, whether it is distorted, and a camera. Here, we mainly analyze the applytransformation function. The first parameter is the difference pointer passed through the gettransformation function, and then we calculate an intermediate angle degrees through the linear difference algorithm according to the difference, The camera class is used to realize the perspective projection after rotating around the Y axis. Therefore, we first obtain the current matrix through t.getmatrix(), and then use camera.translate to translate the matrix and rotate camera.rotatey. In this way, we can easily realize the 3D rotation effect.

Here is the layout file main.xml:

The code of mainactivity is as follows:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>