Reputation: 6188
I'm using this method to detect whether someone clicks on an overlay. Now everything works except for that the click area is too small. So I looked at the api which said "See if a given hit point is within the bounds of an item's marker. ".
I made my bounds bigger like this:
Log.d("debug", "Marker propertie 1: " + marker.getBounds()); //output:Marker propertie 1: Rect(0, 0 - 0, 0)
Rect square = new Rect(0, 0, 200, 200);
marker.setBounds(square);
Log.d("debug", "Marker propertie 2: " + marker.getBounds()); //output:Marker propertie 2: Rect(0, 0 - 200, 200)
if (hitTest(item, marker, x-p.x, y-p.y)) {
//...
}
But both ways of changing its bounds doesn't change the click-area. Can someone hint me how I can increase the clickarea of my drawables?
Upvotes: 1
Views: 1637
Reputation: 61
This is the google maps api? If you want to extend the bound you can overide the hitTest of your extended itemizedOverlay to something like this.
@Override
protected boolean hitTest(OverlayItem overlayItem, Drawable drawable, int x, int y) {
Rect bounds = drawable.getBounds();
int newLeft = (int) (200 * ((double)bounds.left / (double)bounds.width()) ) ;
int newTop = (int) (200 * ((double)bounds.top / (double)bounds.height()) );
Rect square = new Rect(newLeft, newTop, 200, 200);
return square.contains(x, y);
}
Just tested on a map I have seems to work.
Upvotes: 2