2011-05-03 78 views
1

我使用這種方法來檢測是否有人點擊覆蓋。現在一切正常,除了點擊面積太小。所以我看了一下這樣的api:「看看一個給定的生命點是否在一個物品的標記範圍內」。ItemizedOverlay hitTest

我做了我更大的範圍如下:

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)) { 
//... 
} 

但改變其邊界不會改變的點擊區域的兩種方式。有人可以提示我如何增加drawable的點擊面積嗎?

回答

2

這是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); 
} 

剛剛在地圖上測試過,我似乎工作。

+0

還要記住將硬編碼200調整爲適合您的應用程序。我似乎得到了新的界限,所以你應該檢查newTop,看看它是否在你的地圖上正確計算。 – ThomasAha 2011-05-03 11:41:57