Android programming based on custom view to achieve official seal effect example [source code download attached]
This article describes the implementation effect of Android programming based on user-defined view. Share with you for your reference, as follows:
Last time I went to a company for an interview, the interviewer asked a question about how to use Android's custom view to achieve the effect of an official seal. It is said that this is the previous interview question of Huawei. I thought about it. If the effect of the official seal is that the outermost layer is a circle and there is a five pointed star inside, but how to draw this text is difficult. Later, I came back to see the Java API, It is found that the path of others already provides such a method:
Then they explained that the corresponding path is generated according to the angle of the fox line, so we can set a corresponding drawing area for the text to make the drawn text in this area,
Next, we just need to draw the text in this area.
OK, here's the whole code:
First, it inherits from view. We initialize it in the structure. Similarly, in order to facilitate the extensibility of the program, we use custom attributes,
Then we initialize the text, text size, text spacing, text color, etc,
Next, we are rewriting OnDraw (canvas)
Next, there are three corresponding methods: draw a ring, a star, and text
Finally, just reference it in the view we need
Click here to download the complete example code.
More readers interested in Android related content can view the special topics of this site: summary of Android graphics and image processing skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solving methods, summary of Android basic component usage, summary of Android view skills, summary of Android layout skills, and Android control usage summary
I hope this article will help you in Android programming.