First, the basic steps
1. Custom View Properties
2. Get custom attributes in the view's construction method
3. Overriding the Onmesure method (not required)
4. Overriding the OnDraw method
Second, the concrete realization
1, custom View properties, first set up a attrs.xml under the res/values/
Then use it in the layout file, where the red Arrow is followed by the project package name, so that you can use the shortcut keys to elicit the custom properties.
2. Get our custom properties in the View construction method
3, if necessary, must rewrite onmeasure
Before rewriting, understand Measurespec's specmode, altogether three kinds:
Exactly: The general setting of a definite value or a match_parent
At_most: Indicates that the child layout is limited to a maximum value, typically warp_content
UNSPECIFIED: Indicates how large a sub-layout is to be, rarely used
4. Overriding the OnDraw method
4, the Operation effect, click View can randomly change the value, similar to the verification code.
Android Custom View Analysis