Hit testing on a MapView, Android
I hava a MapView and I define a Rect. Touching the map I compare the coordinates to detect whether the rect is touched or not. But it does not wor开发者_如何转开发k
RectF hitTestRecr = new RectF();
hitTestRecr.set(0,100,0,100);
hitTestRecr.offset(0,0);
if (hitTestRecr.contains(event.getX(),event.getY())) {
Toast.makeText(getBaseContext(), "hit", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getBaseContext(), "no hit", Toast.LENGTH_SHORT).show();
}
I always get no hit
any ideas?
It's because your RectF is 0 wide and 0 tall.
set(float left, float top, float right, float bottom)
I think what you want is
hitTestRecr.set(0,0,100,100);
精彩评论