Android custom circular graduated gradient progress bar style example code

design sketch

1、 Draw a ring

The ring is named Si Yi. The first one to draw is the ring

1: Ring drawing function

Ring API

Parameter description

Oval: the elliptical object where the arc is located.

Startangle: the starting angle of the arc.

Sweepangle: the angle of the arc.

Usecenter: whether to display the radius line. True means to display the radius line between the arc and the center of the circle, and false means not to display.

Paint: the brush used when painting.

2: Color the ring

Because the gradient effect is required, the API is also provided

The function name is sweepgradient

Constructor

public SweepGradient (float cx,float cy,int[] colors,float[] positions)

X coordinate of center point of Cx rendering

Y-point coordinates of CY rendering Center

Colorsthe array of colors rendered around the center must have at least two color values

Positions is a color array of relative positions. It can be null. If it is null, the colors are evenly distributed along the gradient line

public SweepGradient (float cx,int color0,int color1)

X coordinate of center point of Cx rendering

Y coordinate of CY rendering center point

Color0 start render color

Color1 end render color

Implementation style

However, the final effect is that the gradient start angle starts from 0 °, but what we want is to start from - 90 °, so we need to rotate the drawn ring

Finally, add a gradient to the torus

Because the gradient of the first ring needs to be maintained, it will be set after using it when drawing

3: Draw remaining progress

The same is the starting angle of the circle

The final implementation effect is shown in Figure 1

2、 Scale

1: Ring scale

It is to divide the whole ring equally according to the scale size, calculate the angle occupied by each ring, and then calculate the display of several rings according to the current progress, and then draw them. The scale is also a ring, but the angle is very small

as follows

2: Text scale

That is, to draw text, rotate the text accordingly after drawing

Finally, the entire view code is added

The above is the Android custom circular graduated progress bar 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
分享
二维码
< <上一篇
下一篇>>