Android GestureListener gesture, multi-finger Scaling

Source: Internet
Author: User

Note:
1. onDown multi-point events still respond to single-point events
2. triggered when onScroll slides, e1 can only get one point, while e2 can get more points. (I don't know why)
3. Add GestureListener to the view.
You can use the following code:
Public class ViewerInnerTouchListener implements OnTouchListener {

Private GestureDetector gestureDetector;

Public ViewerInnerTouchListener (GAViewer viewer ){
GestureDetector = new GestureDetector (new GestureListener (viewer ));
}

Public boolean onTouch (View v, MotionEvent event ){
GestureDetector. onTouchEvent (event );
Return true;
}

}

SetOnTouchListener (new ViewerInnerTouchListener (this ));


Several methods of GestureListener should be understood
// Triggered when the Touch is down, whether it is touch (including long) or scroll
Public boolean onDown (MotionEvent e ){
Return false;
}

// Triggered when Touch is not sliding
// (Compare with onDown and onLongPress
// OnDown must be triggered immediately as long as Touch down.
Public void onShowPress (MotionEvent e ){
}

// Triggered when Touch is down without moving
// After Touchdown, it will trigger onShowPress before onLongPress after a while without sliding.
Public void onLongPress (MotionEvent e ){
}

// The above two functions are triggered when the touch is down without moving (onScroll) or long-pressed (onLongPress.
/**
* Click very fast (do not slide) Touchup: onDown-> onSingleTapUp-> onSingleTapConfirmed
*
Click a slower (do not slide) Touchup: onDown-> onShowPress-> onSingleTapUp-> onSingleTapConfirmed
* Click longpress. onSingleTapUp is not triggered when onScroll is clicked.
*/
Public boolean onSingleTapUp (MotionEvent e ){
Log. I ("onSingleTapUp", "onSingleTapUp ");
Return false;
}

// Triggered when sliding is reached
Public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX,
Float distanceY ){
Return true;
}

// Triggered when up is triggered when a sliding distance is reached.
Public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX,
Float velocityY ){
Return true;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.