the feature is simple to draw on the artboard based on the position of the finger coordinates1.
2. Code implementation
public class Erinieshow extends Relativelayout {context context; Relativelayout BG; MyView myview;int level;public erinieshow (context context, int level) {super (context); This.context = Context;this.level = LEVEL;BG = new Relativelayout (context); MyView = new MyView (context); Bg.addview (MyView); AddView (BG); int[] Resolution = phoneutil.getresolution (context); Relativelayout.layoutparams params = new Relativelayout.layoutparams (resolution[0], phoneutil.getfitheight (context, Bg.setid (100001); Bg.setlayoutparams (params); Myview.setlayoutparams (params), switch (level) {case 0:bg.setbackgroundresource (r.drawable.rewardlevel0); Case 1:bg.setbackgroundresource (R.DRAWABLE.REWARDLEVEL1); Break;case 2:bg.setbackgroundresource ( R.DRAWABLE.REWARDLEVEL2); Break;default:bg.setbackgroundresource (r.drawable.rewardlevel3); break;} Myview.init ("#d3d3d3"), (Color.parsecolor);}}
public class MyView extends TextView {private float touch_tolerance;//fill the distance, make the line more natural, softer, the smaller the value, the softer. Private Bitmap mbitmap;private Canvas mcanvas;private Paint mpaint;private Path mpath;private float MX, My;private boolean Isdraw = False;int Time=0;public MyView (context context) {super (context);} @Overrideprotected void OnDraw (canvas canvas) {super.ondraw (canvas); if (Isdraw) {Mcanvas.drawpath (MPath, mpaint); Canvas.drawbitmap (mbitmap, 0, 0, null);}} /** * Turn on erase function * * @param bgColor * Cover background color * @param paintstrokewidth * Contact (RUBBER) Width * @param touchtolera NCE * Fills the distance, the lower the value, the softer. */public void init (final int bgColor, final int paintstrokewidth,float touchtolerance) {touch_tolerance = touchtolerance; Set Brush Mpaint = new Paint ();//Mpaint.setalpha (0);//brush across the traces will become transparent color mpaint.setcolor (color.black); This cannot be a transparent color mpaint.setxfermode (new Porterduffxfermode (PorterDuff.Mode.DST_OUT));//or//Mpaint.setalpha (0);// Mpaint.setxfermode (New Porterduffxfermode (PorterDuff.Mode.DST_IN)); Mpaint.Setantialias (True); Mpaint.setdither (true); Mpaint.setstyle (Paint.Style.STROKE); Mpaint.setstrokejoin ( Paint.Join.ROUND); Front fillet mpaint.setstrokecap (Paint.Cap.ROUND); Posterior fillet mpaint.setstrokewidth (paintstrokewidth); Pen width//Trace MPath = new Path ();//overwrite Layoutparams layoutparams = Getlayoutparams (); int height = layoutparams.height;int width ; if (Getlayoutparams (). width = = layoutparams.match_parent) {width = n;} else {width = layoutparams.width;} Mbitmap = Bitmap.createbitmap (width, height, config.argb_8888); Mcanvas = new Canvas (MBITMAP); Mcanvas.drawcolor ( BgColor); Isdraw = true;} @Overridepublic boolean ontouchevent (Motionevent event) {if (!isdraw) {return true;} Switch (event.getaction ()) {case Motionevent.action_down://Contact Press//TouchDown (EVENT.GETRAWX (), Event.getrawy ()); TouchDown (Event.getx (), event.gety ()); invalidate (); Break;case motionevent.action_move://Contact Move touchmove (event.getx (), event.gety ()); invalidate (); Break;case motionevent.action_up://Contacts Bounce Touchup (Event.getx (), event.gety ()); InvalidatE (); break;default:break;} return true;} private void TouchDown (float x, float y) {mpath.reset (); Mpath.moveto (x, y); MX = X;my = y;} private void TouchMove (float x, float y) {float dx = math.abs (x-mx); float dy = Math.Abs (y-my); if (DX >= touch_toler ance | | Dy >= touch_tolerance) {mpath.quadto (MX, my, (x + MX)/2, (y + MY)/2), mx = X;my = y;}} private void TouchUp (float x, float y) {mpath.lineto (x, y); Mcanvas.drawpath (MPath, Mpaint); Mpath.reset ();}}
SOURCE Download http://download.csdn.net/detail/strawberry2013/7682865
Android_ Scratch Scratch Award