android - ImageView Is Not Touchable in a View Class When tried to draw on it -
imageview
not touchable in view class when tried draw on ... problem when try draw on imageview
m not able draw on ... tried lot .. not able ..... declared iv.setontouchlistener(this);
still not touchable .. appreciated , thanks!
public class brushview extends view implements ontouchlistener { private paint brush = new paint(); private path path = new path(); public layoutparams params; imageview iv; public brushview(context context) { super(context); brush.setantialias(true); brush.setcolor(color.blue); brush.setstyle(paint.style.stroke); brush.setstrokejoin(paint.join.round); brush.setstrokewidth(15f); iv = new imageview(context); iv.setontouchlistener(this); iv.setbackgroundresource(r.drawable.ic_launcher); params = new layoutparams(layoutparams.match_parent, layoutparams.match_parent); iv.setlayoutparams(params); } @override protected void ondraw(canvas canvas) { canvas.drawpath(path, brush); } @override public boolean ontouch(view v, motionevent event) { float pointx = event.getx(); float pointy = event.gety(); // checks event occurs switch (event.getaction()) { case motionevent.action_down: path.moveto(pointx, pointy); return true; case motionevent.action_move: path.lineto(pointx, pointy); break; case motionevent.action_up: break; default: return false; } // force view draw. postinvalidate(); return false; } }
Comments
Post a Comment