The progressbar font developed by Android scrolls with the loading of the progress bar

I read a lot about the scrolling effect of ProgressBar on the Internet, but I haven't found this effect suitable for the project, so I write this article myself, record the writing process and make a reference for you. First look at the final effect picture

I use the GIF picture recorded by licecap software here. The effect is a little out of frame. Please tell me which brother has a better GIF recording software. I'd like to thank you in advance.

First, look at the XML code. There are only two system controls, a textview and a ProgressBar. The button is just to facilitate the effect of triggering the progress bar. In the actual project, it can be done according to the needs. First, look at the code in XML:

Styles: ProgressBar_ color.xml

Get the width of the control in oncreate() method. The code is as follows:

First say the specific implementation ideas, and then paste the final code

The implementation idea is that when the progressbar reaches the maximum value, the position of textview will be moved to the farthest place. To get any percentage of the progressbar that can be moved to the corresponding percentage, we need to know the distance each percentage moves. If what you said is not clear enough, let's look at the following formula to better understand it.

//The minimum unit of the progress bar is 1 by default. You can also use other values. I used 1 in the demo for convenience:

Minimum unit of progress bar / maximum value of progress bar = distance moved by each percentage / total distance (total width of control)

You can derive:

Distance to be moved for each percentage = (minimum unit of progress bar / maximum value of progress bar) * total distance (total width of control)

Because we want to do mobile animation effect, in order to avoid anr, we directly open a branch process to control the interface. The main codes are as follows

It's done, but when we run it, we find that when the progressbar reaches the maximum value, the font on it exceeds the screen range and can't be seen. The effect is shown in the figure:

This has caused great confusion to users. Calm down and analyze it. You can know that textview has been corresponding to the right side of ProgressBar data, and its language skills are not very good. Let's see the figure above:

It can be seen that when the data is 0%, it is on the right side of the corresponding data of the progressbar. When the data is the maximum value, it is not enough to exceed the screen display. Now, if we want the progressbar to be displayed when it is the maximum value, we need not offset when the offset distance plus the font width and the padding value on the right side of the font are greater than the progressbar width. Then modify the code as follows:

Let's run it and see the effect:

Here we are finished. If there is anything unclear or wrong, please leave a message and correct it. I will reply as soon as possible. Friends who need the source code can go to GitHub to download, and give the GitHub address with both hands: the font rolls with the loading of ProgressBar.

summary

The above is what Xiaobian introduced to you. The progressbar font of Android development rolls with the loading of the progress bar. 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
分享
二维码
< <上一篇
下一篇>>