2012-04-18 75 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 

      } 
      } 

......      
    } 
相关问题