android - How I can paint stroke around circle? -


i creating circle programmatically. how can paint stroke around circle ?

for example need :

enter image description here

bellow code :

public class draw extends view {     boolean flag = false;     private static class circlearea {         int radius;         int centerx;         int centery;          circlearea(int centerx, int centery, int radius) {             this.radius = radius;             this.centerx = centerx;             this.centery = centery;         }          @override         public string tostring() {             return "circle[" + centerx + ", " + centery + ", " + radius + "]";         }     }      private paint mcirclepaint;     private static final int circles_limit = 1;     private hashset<circlearea> mcircles = new hashset<circlearea>(circles_limit);     private sparsearray<circlearea> mcirclepointer = new sparsearray<circlearea>(circles_limit);       public draw(final context ct) {         super(ct);         init(ct);     }       private void init(final context ct) {          mcirclepaint = new paint();          mcirclepaint.setcolor(color.blue);         mcirclepaint.setstrokewidth(40);         mcirclepaint.setstyle(paint.style.fill);     }      @override     public void ondraw(final canvas canv) {          (circlearea circle : mcircles) {             canv.drawcircle(circle.centerx, circle.centery, circle.radius, mcirclepaint);         }     }      @override     public boolean ontouchevent(final motionevent event) {         boolean handled = false;         circlearea touchedcircle;         int xtouch;         int ytouch;         int pointerid;         int actionindex = event.getactionindex();          // touch event coordinates , make transparent circle         switch (event.getactionmasked()) {            case motionevent.action_down:                  clearcirclepointer();                  xtouch = (int) event.getx(0);                 ytouch = (int) event.gety(0);                  touchedcircle = obtaintouchedcircle(xtouch, ytouch);                 touchedcircle.centerx = xtouch;                 touchedcircle.centery = ytouch;                 mcirclepointer.put(event.getpointerid(0), touchedcircle);                  invalidate();                 handled = true;                 break;             case motionevent.action_move:                 final int pointercount = event.getpointercount();                  (actionindex = 0; actionindex < pointercount; actionindex++) {                     pointerid = event.getpointerid(actionindex);                     xtouch = (int) event.getx(actionindex);                     ytouch = (int) event.gety(actionindex);                     touchedcircle = mcirclepointer.get(pointerid);                      if (null != touchedcircle) {                         touchedcircle.centerx = xtouch;                         touchedcircle.centery = ytouch;                     }                 }                 invalidate();                 handled = true;                 break;              case motionevent.action_up:                 clearcirclepointer();                 invalidate();                 handled = true;                 break;              case motionevent.action_pointer_up:                 pointerid = event.getpointerid(actionindex);                  mcirclepointer.remove(pointerid);                 invalidate();                 handled = true;                 break;              case motionevent.action_cancel:                 handled = true;                 break;              default:                 // nothing                 break;         }          return super.ontouchevent(event) || handled;     }      private void clearcirclepointer() {         mcirclepointer.clear();     }     private circlearea obtaintouchedcircle(final int xtouch, final int ytouch) {         circlearea touchedcircle = gettouchedcircle(xtouch, ytouch);         if (null == touchedcircle) {             touchedcircle = new circlearea(xtouch, ytouch, 50);              if (mcircles.size() == circles_limit) {                 // remove first circle                 //mcircles.clear();             }             if (flag == false) {                 mcircles.add(touchedcircle);                 flag = true;             }          }          return touchedcircle;     }     private circlearea gettouchedcircle(final int xtouch, final int ytouch) {         circlearea touched = null;          (circlearea circle : mcircles) {             if ((circle.centerx - xtouch) * (circle.centerx - xtouch) + (circle.centery - ytouch) * (circle.centery - ytouch) <= circle.radius * circle.radius) {                 touched = circle;                 break;             }         }          return touched;     } } 

you need use separate paints different styles.

paint fillpaint; paint strokepaint; fillpaint.setstyle(paint.style.fill); strokepaint.setstyle(paint.style.stroke);  canvas.drawcircle(circle.centerx, circle.centery, circle.radius, fillpaint); canvas.drawcircle(circle.centerx, circle.centery, circle.radius, strokepaint); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -