2012-04-18 98 views

回答

1

獲取特定位置的Rect座標並檢查拖動的項目座標是否與位置衝突Rect coords。您可以使用Rect.contains() api進行檢查。如果它返回true,則可以顯示警報。

if (locationRect.contains(drag.left, drag.top, drag.right, drag.bottom)) { 
    // Show Alert dialog 
} 
+0

這樣做幫助嗎?... – Ronnie 2012-04-24 12:10:30

0

我覺得你有onTouch方法在你的代碼..

@Override 
    public boolean onTouch(View v, MotionEvent event) { 

    switch(event.getAction()) 
     { 
    case MotionEvent.ACTION_DOWN: 
      ..... 
      break; 
     case MotionEvent.ACTION_MOVE: 
     int x_cord = (int)event.getRawX(); 
     int y_cord = (int)event.getRawY(); 
     //if you want the alert when the image enters a square of (10,10) (25,25),(10,25) and (25,10).. then 
     if(x_cord>=10 && x_cord<=25) 
     { 
     if(y_cord>10 && y_cord<25){<-- these cordinates work if the image you are moving is a square of side 15 .. so you can change accordingly.. 
     //alert here 

      } 
      } 

......      
    } 
相關問題