:
View code: display the view in the activity.
Package COM. tszy. view; import android. content. context; import android. graphics. bitmap; import android. graphics. bitmap. config; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. graphics. path; import android. view. motionevent; import android. view. view;/*** dual-buffer drawing demo tablet ** @ author jianbinzhu **/public class view7 extends view {private paint; private canvas cachecanvas; private bitmap cachebbitmap; private Path; Public view7 (context) {super (context); // todo auto-generated constructor stubpaint = new paint (); paint. setantialias (true); paint. setstrokewidth (3); paint. setstyle (paint. style. stroke); paint. setcolor (color. cyan); Path = New Path (); cachebbitmap = bitmap. createbitmap (480,320, config. argb_8888); cachecanvas = new canvas (cachebbitmap);} @ overrideprotected void ondraw (canvas) {canvas. drawcolor (color. black); // draw the last image; otherwise, the canvas is inconsistent. drawbitmap (cachebbitmap, 0, 0, null); canvas. drawpath (path, paint);} private float cur_x, cur_y; private Boolean ismoving; @ overridepublic Boolean ontouchevent (motionevent event) {// todo auto-generated method stubfloat x = event. getx (); float y = event. gety (); Switch (event. getaction () {Case motionevent. action_down: {cur_x = x; cur_y = y; Path. moveTo (cur_x, cur_y); ismoving = true; break;} case motionevent. action_move: {// draw the path using the quadratic curve. quadto (cur_x, cur_y, x, y); // The following method looks like above // path. lineto (x, y); cur_x = x; cur_y = y; break;} case motionevent. action_up: {// click it to save the last state of cachecanvas. drawpath (path, paint); Path. reset (); ismoving = false; break ;}// refresh the interface invalidate (); Return true ;}}