android - How to detect movement to the left, right, up and down -
i wonder if it's possible use ontouch method below detect if user moving finger left, right, och down on screen. have grid objects , want user able move 1 of object in 4 directions.
my idea use action_down event x , y position , check objects in list see object whitin x , y value. using action_move start moving in 1 of directions.
@override public boolean ontouch(view v, motionevent event) { switch (event.getaction()) { case motionevent.action_down: log.i("test","down"); break; case motionevent.action_pointer_up: break; case motionevent.action_move: log.i("test","move"); break; }
public class mainactivity extends activity { ... // example shows activity, use same approach if // subclassing view. @override public boolean ontouchevent(motionevent event){ int action = motioneventcompat.getactionmasked(event); switch(action) { case (motionevent.action_down) : log.d(debug_tag,"action down"); return true; case (motionevent.action_move) : log.d(debug_tag,"action move"); return true; case (motionevent.action_up) : log.d(debug_tag,"action up"); return true; case (motionevent.action_cancel) : log.d(debug_tag,"action cancel"); return true; case (motionevent.action_outside) : log.d(debug_tag,"movement occurred outside bounds " + "of current screen element"); return true; default : return super.ontouchevent(event); } }
for more details see this link, can use (and recommend that) onfling() of gesturedetector example of visit this link...
Comments
Post a Comment