我想實現這個方法:如何獲取ImageView的4個座標?
//#OnTouchEvent()
public boolean onTouchEvent(MotionEvent event) {
//Coordinates of the touch
int x = (int) event.getX();
int y = (int) event.getY();
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Check if the touch is within the coordinates of an image
if x isBetweenCoordinatesXofTheImage
if y isBetweenCoordinatesYofTheImage
//DoSomething
else
//DoNothing
break;
case MotionEvent.ACTION_MOVE:
//nothing
break;
case MotionEvent.ACTION_UP:
//check if the touch is within the coordinates of an image;
if x is betweenCoordinatesX of the image
y is betweenCoordinatesYofTheImage
//DoSomething
else
//DoNothing
break;
}
return true;
}
的ImageView的有4個coorners,我需要知道的4點座標(X,Y)之前做檢查。 左上角的X座標與左下角相同,右上角的X座標與右下角相同。對於Y座標是相似的。 我的問題是:我如何獲得ImageView的4個座標?
感謝大家!
我知道我錯過了一些東西。 x,y,x +寬度,y +高度 – Simon
爲什麼不在您的imageview上使用view.ontouchlistener? – njzk2
我知道這種方法,但我需要按照我指出的方式來做。我需要在兩個圖像之間進行匹配移動。我需要按下屏幕並將手指拖到下一張圖像上,而不用擡起手指。如果我使用你的方法,方法OnTouchEvent不會執行。謝謝! – Adrian