Android realizes the data loading effect of imitation meituan and SF express

We all know that there are two common animation modes in Android: frame animation and tween animation. Frame animation provides an animation mode of playing pictures frame by frame. Playing the pre prepared images is similar to the principle of GIF pictures, just like playing a movie. Patching animation can realize the effects of moving, zooming in, zooming out and gradient of view components@ H_ 403_ 1@

Today, we will mainly imitate the dialog box effect of villain running animation when loading data in meituan. An interesting name is running man. Run, brother! I don't have much to say. First, I'll show you the effect you want to achieve, and then decide whether to read next, because as programmers, our time is very precious. After all, we don't have a girlfriend@ H_ 403_ 1@

(PS: for technical reasons, the effect of the dynamic picture provided is not very obvious, but it runs very well on the mobile phone. Interested friends can download the source code to have a look.)

Let's talk about the implementation principle. First, create an anim folder in the res directory of the project, and then create an XML file. Add the following code:

Animation list is an animation list with many items in the middle, that is, the pictures that make up the animation frame, @ H_ 403_ 1@

Android: drawable [drawable] / / load drawable object @ h_ 403_ 1@

Android: duration [long] / / duration of each frame of animation (unit: ms) @ h_ 403_ 1@

Android: oneshot [Boolean] / / whether the animation runs only once, true once and false repeatedly

After writing, let's customize a dialog box to automatically load the animation of running when the dialog box is opened. See code:

We can see that in the code, we use an imageview.post (runnable R) method. Because the frame animation needs to be redrawn continuously, it must be run in the thread, otherwise we can only see the effect of the first frame. This is the same as the principle of our game. When a character moves, there is a thread controlling the continuous redrawing of the picture@ H_ 403_ 1@

Of course, there is another method that can also be realized:

Finally, it is called in Activity.

For customprogressdialog, this custom dialog class is well encapsulated and easy to call. You can quickly replace it with the effect you want. Just change the picture.

The above is the whole content of this article. If you don't understand anything after the test, you can introduce it in the message area below. Thank you for your support for 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
分享
二维码
< <上一篇
下一篇>>