Main ideas:
Design a view into multi-layer: Background layer, including winning information, etc.;
Covering layer, used for scraping prizes, using a bitmap to associate a canvas
On the bitmap, use its Canvas.drawpath API to handle gesture sliding (similar to the scraping award)
Use Paint.setxfermode to remove the gesture slip area
public class Guaview extends View {private Bitmap mbitmap;//obscured layer private Canvas mcanvas;//Draw Overlay Layer Private P
Aint mouterpaint;
Private Path MPath;
private float mlastx;
private float mlasty; Private Bitmap Mcoverbitmap;
Cover Figure private int mwidth, mheight;
Private Paint Minnerpaint;
Private String MInfo;
Public Guaview {This (context, NULL);
Public Guaview (context, AttributeSet attrs) {Super (context, attrs);
Init ();
private void Init () {mpath = new Path ();
Mouterpaint = new Paint ();
Minnerpaint = new Paint ();
Mcoverbitmap = Bitmapfactory.decoderesource (Getresources (), R.drawable.fg_guaguaka);
MInfo = "¥5 0 0"; @Override protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {super.onmeasure (widthmeas
Urespec, Heightmeasurespec);
Mwidth = Mcoverbitmap.getwidth ();
Mheight = Mcoverbitmap.getheight (); SetmeasureDdimension (Mwidth, mheight);
Mbitmap = Bitmap.createbitmap (Mwidth, Mheight, Bitmap.Config.ARGB_8888);
Mcanvas = new Canvas (MBITMAP);
Mcanvas.drawbitmap (mcoverbitmap, 0, 0, NULL);
Setouterpaint ();
Setinnerpaint ();
private void Setinnerpaint () {minnerpaint.setcolor (color.red);
Minnerpaint.setstyle (Paint.Style.STROKE);
Minnerpaint.setstrokecap (Paint.Cap.ROUND);
Minnerpaint.setstrokejoin (Paint.Join.ROUND);
Minnerpaint.setantialias (TRUE); Minnerpaint.setdither (TRUE);
Anti-Stabilization Minnerpaint.setstrokewidth (5);
Minnerpaint.settextsize (100);
Minnerpaint.settextalign (Paint.Align.CENTER);
private void Setouterpaint () {mouterpaint.setcolor (color.green);
Mouterpaint.setstyle (Paint.Style.STROKE);
Mouterpaint.setstrokecap (Paint.Cap.ROUND);
Mouterpaint.setstrokejoin (Paint.Join.ROUND);
Mouterpaint.setantialias (TRUE); Mouterpaint.setdither (TRUE); Anti-stabilization Mouterpaint.setstrokewidth (20);
@Override//path Public boolean ontouchevent (Motionevent event) {float x = Event.getx ();
Float y = event.gety ();
Switch (event.getaction ()) {Case MotionEvent.ACTION_DOWN:mLastX = x;
Mlasty = y;
Mpath.moveto (x, y);
Break
Case MotionEvent.ACTION_MOVE:float DeltaX = Math.Abs (X-MLASTX);
float DeltaY = Math.Abs (y-mlasty);
if (DeltaX > 5 | | deltay > 5) {mpath.lineto (x, y);
} MLASTX = x;
Mlasty = y;
Break
Case MotionEvent.ACTION_UP:break;
Invalidate ();//Call OnDraw return true;
} @Override protected void OnDraw (Canvas Canvas) {Super.ondraw (Canvas); Canvas.drawcolor (Color.parsecolor ("#bbbbbb")); Background color gray Canvas.drawtext (MInfo, MWIDTH/2, MHEIGHT/4 * 3, Minnerpaint); Draw Text Canvas.drawbitmap (mbitmap, 0, 0, NULL); Draw Mbitmap This is a variable bitmap, drawn by Mcanvas, first drawnThe Mcoverbitmap DrawPath (); The private void DrawPath () {///MODE:DST intersects with SRC, preserves only DST and removes the intersecting partial mouterpaint.setxfermode (new Porterduffxfe
Rmode (PorterDuff.Mode.DST_OUT));
Mcanvas.drawpath (MPath, mouterpaint);
}
}
Paint.join Continuous Brush Cohesion:
- Miter the outer edge with an acute angle
- ROUND with an arc
- Bevel with a straight line
PAINT.CAP specifies how the start and end points for lines and paths (lines and paths) are handled:
- Butt ends with the path does not surpass it
- ROUND with the center in the path semicircle
- Square with the center in the path square