Android custom view circular progress bar control (III)

Continue to practice customizing the view. The circular progress bar control brought this time is similar to the previous circular percentage control. This time, knowledge points such as gradient rendering and canvas rotation are involved. The effects are as follows:

Although the steps are similar, I still want to write. After all, the basic thing is to practice more

1. Create a new attrs.xml file in the RES / values folder and write custom attributes:

2. Create a new circleprogressview, inherit the view, and override the construction method:

3. Get the value of the custom attribute in the third constructor:

4. Objects used to create drawings, such as paint, rect, rectf:

5. Override the onmeasure() method to calculate the width and height of the custom view:

6. Rewrite ondraw() method, draw arc, scale line, percentage text and label description text, and pay attention to the calculation of coordinates:

7. Expose a method to dynamically set the percentage:

8. In activity_ Use this view in the main.xml layout file:

9. Set listening in mainactivity. Incoming percentage:

Code download address: https://github.com/MonkeyMushroom/CircleProgressView/tree/master

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