1
我正在尝试开发一个应用程序,在该应用程序中,我可以将图像拖动到屏幕中的特定位置,并在其右侧位置,现在拖动部分完成,我只需要验证位置并在图像位于特定位置时显示警报将图像拖动到屏幕上的特定位置并提醒其位置是否正确-Android-
我正在尝试开发一个应用程序,在该应用程序中,我可以将图像拖动到屏幕中的特定位置,并在其右侧位置,现在拖动部分完成,我只需要验证位置并在图像位于特定位置时显示警报将图像拖动到屏幕上的特定位置并提醒其位置是否正确-Android-
获取特定位置的Rect
坐标并检查拖动的项目坐标是否与位置冲突Rect coords。您可以使用Rect.contains()
api进行检查。如果它返回true,则可以显示警报。
if (locationRect.contains(drag.left, drag.top, drag.right, drag.bottom)) {
// Show Alert dialog
}
我觉得你有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
}
}
......
}
这样做帮助吗?... – Ronnie 2012-04-24 12:10:30