Android realizes snail progress bar effect

The friendly interface can impress users and add points to the app. Today's progress bar tells users the current progress in the way of snail crawling. The experience is great. Let's share it here.

Here, a set of frame animation is created as the flag of the progress bar, as follows:

Set the onshot property value to false to ensure that the animation can cycle all the time. Five pictures are added here. They rotate every 300 milliseconds to form a group of smooth animation.

The custom view inherits from seekbar, as follows:

This control is introduced into the layout file. The code is as follows:

Control logic in mainactivity.java. The code is as follows:

The logic is also relatively simple. Use the handler to form a loop. First, judge that when the progress is less than 20, send a message every 500 milliseconds (normal progress); When judging that the progress is 21-26, send a message every 1000 milliseconds (the slowest progress); When judging the progress of 27-100, send a message every 50 milliseconds (the fastest progress).

Run this instance as follows:

It can be seen from the above figure that it seems unreasonable for a stupid snail to move his head and feet at the end of his climb. We can monitor the progress of seekbar. When the progress is 100, stop the animation. Add the following code to the above code to monitor the progress:

Each time the progress changes, the method onprogresschanged will be called back continuously. Therefore, in this method, it is judged that if the progress is 100, the animation will be stopped. At this time, run the example again 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
分享
二维码
< <上一篇
下一篇>>