Android imitation coin rotation wechat red envelope animation effect

The project needs to study the wechat red envelope animation, that is, the effect of coin rotation. In fact, the principle is to play three pictures from different angles with animationdrawable frame animation. After referring to the case, record the completed process for yourself.

1. Define animation in XML file:

The steps are as follows:

① New Android project

② Create an anim.xml in the drawable directory (note that the file name is lowercase)

The root tag is animation list, where oneshot represents whether to display only once. If it is set to false, the animation will be played repeatedly. Under the root tag, each picture in the animation is declared through the item tag. Android: duration indicates the length of time the picture is displayed. The rotation speed of the picture can be set through this parameter. Other attributes can find data by themselves~

2. Set the layout file. The effect and code are as follows

3. Realize the effect of red envelope pop-up window. The effect and code are as follows:

The steps are as follows:

① Custom red envelope pop-up dialog class: the red code part is the start animation part

② Add a dialog in the system style file

(3) call the custom Diaog class in MainActivity and instantiate it, and set the ratio of the red envelope to the screen, otherwise the red envelope will occupy the entire screen, and the red code will set the size code.

4. For the two results after clicking, that is, the two results of snatching and not snatching, you can jump to the success class through intent or jump out of the simple logic of the failure pop-up window.

① Grab the effect picture. The interface here is relatively simple, so you don't post code.

② The rendering of the failed pop-up window. The user-defined pop-up window code here is basically similar to the red envelope pop-up window code. The difference is that there is only one button to remove the red envelope, and the layout is relatively simple, so it will not be posted. It is mainly necessary to use proportion to plan the location of several components (refer to the red envelope code above), otherwise it cannot adapt to multiple screens, Compression and tension deformation will occur.

Here, the rough red envelope animation effect is basically completed! Of course, if you need network requests in practical applications, you can join them according to business requirements.

The above is the animation effect of Android imitation coin rotation wechat red envelope introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>