5 minutes to quickly achieve Android explosion smash cool animation effects example

This breaking animation is similar to the explosion breaking effect when Xiaomi system deletes the application.

Rendering display

Let's take a look at the dynamic effect. If you don't feel that it's an ideal learning goal, skip it to avoid wasting everyone's time. ��

Source code here: point_ right: https://github.com/ReadyShowShow/explosion

One line of code calls the animation

Let's begin our official explanation of cool Android animation effects: point_ down:

Let's first grasp the overall structure

The overall structure is very simple and clear, which can be quickly understood by new and old practitioners and easy to grasp and learn.

dismember an ox as skillfully as a butcher

The detailed analysis of each class begins below

Based on the principle of from simplicity to complexity, from the outside to the inside, explain each category in detail

MainActivity.java

Mainactivity.java is the interface for testing dynamic effects. There are 7 test buttons inside the activity. What this class does is very simple, that is, bind click click events to each view separately, so that the view can trigger explosion and fragmentation animation when clicking.

ParticleModel.java

Particlemodel.java is a model that contains all the information of a particle. The advance method calculates the position and color of particles according to the progress returned by the value animation

ExplosionAnimation.java

Exlosionanimation.java is an animation class. It is a value animation. Each time a value animation generates a value, the state of all particles in the whole explosion and fragmentation dynamic effect is calculated. These states are displayed by the view used during rendering.

ExplosionField.java

Explosionfield.java is the real implementation of the explosionanimator above. Explosionfield will create a view and attach it to the root view of the activity.

Why create a new view (explosionfield) when the animation is executed

In fact, the above animation class explosionanimator has realized the core functions. It should be no problem to use the animation directly on the original view. Why introduce an explosionfield class? Why can't the animation be executed directly on the original view? It must be executed on a seemingly redundant explosionfield object.

Here we have to explain from the view drawing principle under Android: the view under Android has a bound. When the view measures and layout, the size and position of the view have been determined. If you want to animate on this view, the animation can only be displayed in a large and small range of the view. Of course, this is not to say that this action effect cannot be achieved on the original view, but it is quite complex. It is quite complex to constantly change the size and properties of the original view during the animation execution.

On the premise that the performance is OK, give priority to the cleanliness of the code, and try to avoid abandoning clean and refreshing code in order to optimize the performance. Generally speaking, excessive optimization does not bring too much experience improvement to users, but brings great maintenance difficulty to the project.

UIUtils.java

Uiutils is a tool class about UI. There's nothing to say

end

Source code: point_ right: https://github.com/ReadyShowShow/explosion

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