我正在使用这个示例:https://github.com/galex/android-mapviewballoons
我的问题是,可点击区域比标记本身宽。例如,我的Google地图标记是25x25,那么可点击区域将延伸到70x70。这对于重叠的标记来说是一个大问题。
当我点击那个箭头尖时,即使点击区域距离标记很远,onTap也会被激活。
请帮忙解决。谢谢。
请帮忙解决。谢谢。
这是ItemizedOverlay
的默认行为。25x25像素通常不足以成为大多数人手指触摸的区域。
如果您想修改覆盖物项的命中测试方式,您应该重写hitTest()
方法。
调试:
尝试为视图使用{{link1:TouchDelegate
}},您可以为给定的View
指定触摸矩形
一个示例展示如何使用TouchDelegate
:
public class TouchDelegateSample extends Activity {
Button mButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.touch_delegate_view);
mButton = (Button)findViewById(R.id.delegated_button);
View parent = findViewById(R.id.touch_delegate_root);
// post a runnable to the parent view's message queue so its run
after
// the view is drawn
parent.post(new Runnable() {
@Override
public void run() {
Rect delegateArea = new Rect();
Button delegate = TouchDelegateSample.this.mButton;
delegate.getHitRect(delegateArea);
delegateArea.top -= 200;
TouchDelegate expandedArea = new TouchDelegate(delegateArea,
delegate);
// give the delegate to an ancestor of the view we're
delegating the
// area to
if (View.class.isInstance(delegate.getParent())) {
((View)delegate.getParent()).setTouchDelegate(expandedArea);
}
}
});
}
}
检查给定的触点是否在项目标记的范围内。 重写以修改项目的命中测试方式。 触点相对于标记的边界。 默认实现只是检查触点是否在标记的可触摸边界内。
View.getHitRect()
。我认为这会很有帮助。 - Reno