When the user clicks on an image view my app does stuff, and when the user finger goes up, it also does stuff, my question is, how can I check when the users finger strays off the image view, but is still pressing the screen, sort of a MOUSE_OUT in flash… so far I have:
myImageView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
break;
}
return true;
}
});
}
You will need to catch
ACTION_MOVEevents, and see if they stray outside theImageViewbounds.In order to do this, you’ll need to catch the events not on the ImageView, but on a View that covers it and the surrounding area (as the ImageView won’t be able to see interaction outside its own bounds). Depending on how much space you have around your
ImageView, and whether there are other elements you want to interact with by touch immediately around it, this could get slightly tricky, as you’ll need to work out atACTION_DOWNwhich element was touched.