Answer the question
In order to leave comments, you need to log in
Why doesn't invalidate(rect) work?
Why does the following code redraw the entire canvas and not the Rect specified?
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(rect != null) {
canvas.drawRect(rect, paint);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
float posX = event.getX();
float posY = event.getY();
int size = 50;
int x = (int) Math.floor(posX / size) * size;
int y = (int) Math.floor(posY / size) * size;
rect = new Rect(x, y, x + size, y + size);
invalidate(rect);
break;
}
return true;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question