开发者

How do you check for someone touching the screen and dragging in a specific direction?

I want to check for someone placing their finger on the center of the screen and dragging to the right, how could this be accomplished?

SOLUTION: http://www.codeshogun.com/blog/2009/04/16/how-to-implement-s开发者_StackOverflow社区wipe-action-in-android/


You could implement the onTouchListener and do something like this:

public boolean onTouch(View view, MotionEvent event) {
  int currentX = event.getX();    

  if(event.getAction() == MotionEvent.ACTION_MOVE) {
    // oldX would be defined as a private property of the class (most likely an Activity)
    if(currentX > oldX) {
      // moving right

      oldX = currentX;
    } else {
      // moving left or not moving at all

      oldX = currentX;
    }
  }

  return true;
}

You can probably play around with that and make it work the way you want.


Look into the GestureDetector class

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜