我正在使用这个方法来检测是否有人点击了覆盖图。现在,除了单击区域太小之外,一切都可以正常工作。所以我看了看api,它说“看看一个给定的命中点是否在一个物品的标记的范围内”。
我将我的边界做得更大,如下所示:
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)) {
//...
}但是这两种改变边界的方法都不会改变点击区域。有人能提示我如何增加我的绘图的点击面积吗?
发布于 2011-05-03 18:08:34
这就是google maps api?如果你想扩展这个界限,你可以重写你的扩展itemizedOverlay的hitTest,如下所示。
@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);
}刚刚在我的地图上测试过了,看起来很有效。
https://stackoverflow.com/questions/5866588
复制相似问题