I'm drawing circles to the canvas ever开发者_StackOverflow社区y time I touch the screen. I add them to an arraylist of paths in the onTouch method. In my onDraw method, I loop through the array, drawing them.
When I try to change the paint of one of the circles, it changes them all. I don't want this, just want it to apply to one specific circle. How can I do that?
Code:
//on touch method
case MotionEvent.ACTION_DOWN:
mode = Drag;
x =(int) event.getX();
y =(int) event.getY();
path = new Path();
path.addCircle(event.getX(), event.getY(), 8, Path.Direction.CCW);
mpaint.setARGB(255, mcolor[0],100, mcolor[2]);
circle.add(path);
invalidate();
//on draw method
for (Path c : circle) {
canvas.drawPath(c, mpaint);
}
Two options:
- Store a separate Paint object along with each circle
- Query the Paint for the current values of whatever you are changing, and then restore them after drawing the circle.
精彩评论