When the user clicks on an image v开发者_开发问答iew 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_MOVE
events, and see if they stray outside the ImageView
bounds.
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 at ACTION_DOWN
which element was touched.
精彩评论