为什么getLocationOnScreen(location)方法会在Android中更改图像的位置时给出相同的结果?
我想拖动图像并在屏幕上找到该图像的最后一个位置。我使用了下面的代码,每次我在屏幕上拖动它时,它都会给出相同的位置。我怎样才能找到它的位置这个代码有什么问题。提前谢谢为什么getLocationOnScreen(location)方法会在Android中更改图像的位置时给出相同的结果?,android,Android,我想拖动图像并在屏幕上找到该图像的最后一个位置。我使用了下面的代码,每次我在屏幕上拖动它时,它都会给出相同的位置。我怎样才能找到它的位置这个代码有什么问题。提前谢谢 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { view.onMove(-distanceX, -distance
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
view.onMove(-distanceX, -distanceY);
int[] location= new int[2];
view.getLocationOnScreen(location);
Integer x=location[0];
Integer y=location[1];
Log.i("Location x1-->",x.toString());
Log.i("Location y1-->",y.toString());
return true;
}
public void onMove(float dx, float dy) {
translate.postTranslate(dx, dy);
invalidate();
}
Thw日志始终显示该数字
05-01 12:07:01.264:I/位置x1-->(397):24
05-01 12:07:01.264:I/位置y1-->(397):100您可以使用
onTouch
事件,并获得如下所述的拖放位置