Customizing a drawcircle Inherit view
To implement a construction method:
Public drawcircle (Context context) { Super(context); this. Mcontext = context; } Public drawcircle (Context context, AttributeSet attrs) { Super(context, attrs); this. Mcontext = context; }
To override the OnDraw method:
protected void OnDraw (Canvas canvas) { super .ondraw (c Anvas); Rimpaint = new Paint (); Circlebounds = new RECTF (2, 2,, 52 true ); Rimpaint.setstyle (Paint.Style.STROKE); Rimpaint.setstrokewidth (Rimwidth); Rimpaint.setcolor (Color.Black); Canvas.drawarc (Circlebounds, N, +, false //Draw line Canvas.drawline (0, 0, Rimpaint,--);
}
If you need to redraw the view, you need to define a method, call invalidate ();
Typically, you set the method in a custom view:
Public void Setdrawview () { // do something invalidate (); }
You can redraw a custom view with X.setdrawview.
The above method can be used to achieve the animation effect generally.
PS: The code is only the interception part, in fact, the main thing is to understand the principle of the view, as well as some common methods of painting,
DrawArc (), the definition of the DrawLine () parameter can be referenced in the description document
Android Custom View Draw Circle Line