Wednesday, October 19, 2011

[android-developers] obtain rectangle on touch

Hello,
I don't know much about Android and I would like to know if you people
could help.
I draw a board using this:
private Rect selRect = new Rect();
for (int x = 0; x <20; x++) {
if( x%2!=0 ) paint.setColor(Color.CYAN);
else paint.setColor(Color.GREEN);
for ( int y = 0; y < 20; y++) {
if ((x%2==0 && y%2==0) || (x%2!=0 && y%2 !=0))
paint.setColor(Color.GREEN);
else paint.setColor(Color.CYAN);
selRect = new Rect(x*squareSize, y*squareSize, (x
+1)*squareSize, (y+1)*squareSize);
canvas.drawRect(selRect, paint);
}
}

so I wanted that using the event onTouch wherever I touch it
"selects" (paints it in a diferent color) that square that I touched.
so far I only reached the event.getX() and event.getY() but I don't
know how those can be usefull to get the whole square that was
touched.

Thanks in advance, any help would be much appreciated.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment