开发者

Hit testing on a MapView, Android

开发者 https://www.devze.com 2023-01-12 05:46 出处:网络
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

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消