[英]Check if MotionEvent.ACTION_UP is out of the imageview
The user will touch a image and it is important that if he left his finger up in that image or not 用户将触摸图像,如果他将手指放在该图像中是非常重要的
i tried with writing a onTouchListner()
and after that using swich case
but i don't know how to continue 我尝试写一个
onTouchListner()
,之后使用swich case
但我不知道如何继续
image.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
break;
}
return true;
}
});
thank's in advance 提前致谢
I found my answer through this link but i change it to this: 我通过此链接找到了答案,但我将其更改为:
private Rect rect; // Variable rect to hold the bounds of the view
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
if (!rect.contains(v.getLeft() + (int) event.getX(), v.getTop() + (int) event.getY())) {
// User moved outside bounds
}
break;
case MotionEvent.ACTION_DOWN:
rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
break;
}
return false;
}
不要忘记MotionEvent.ACTION_CANCEL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.