Android custom view circular percentage control (I)

Do a small exercise to customize the view. The effect is as follows

Just draw a circle, an arc, a percentage text, add a click event, and pass in the percentage redraw

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

2. Create a new circlepercentview, 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 circle, arc and percentage text, and pay attention to the calculation of coordinates:

7. Set the click event for this view to expose a method of dynamically setting the percentage:

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

9. Set listening in mainactivity.java. Incoming percentage:

Code download address: https://github.com/MonkeyMushroom/CirclePercentView/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
分享
二维码
< <上一篇
下一篇>>