Android touch gesture OnGestureListener

Source: Internet
Author: User

OnGestureListener can handle some simple touch gestures, such as sliding and long-pressing. OnGestureListener cannot directly set listening. OnTouchListener can be set, point it to OnGestureListener [java] public class GestureView extends View implements OnTouchListener, OnGestureListener {GestureDetector mGestureDetector; public GestureView (Context context) {super (context); this. setOnTouchListener (this); mGestureDetector = new GestureDetector (this) ;}@ Override public boolean onDown (MotionEvent e) {Log. I ("@ fred", "touch gesture: onDown"); return true ;}@ Override public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {if (e2.getX ()-e1.getX ()> 50) {Log. I ("@ fred", "touch gesture: onFling");} return true ;}@ Override public void onLongPress (MotionEvent e) {Log. I ("@ fred", "touch gesture: onLongPress") ;}@ Override public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {Log. I ("@ fred", "touch gesture: onScroll"); return true ;}@ Override public void onShowPress (MotionEvent e) {Log. I ("@ fred", "touch gesture: onShowPress") ;}@ Override public boolean onSingleTapUp (MotionEvent e) {Log. I ("@ fred", "touch gesture: onSingleTapUp"); return true ;}@ Override public boolean onTouch (View v, MotionEvent event) {// upload the MotionEvent event to GestureDetector return mGestureDetector. onTouchEvent (event) ;}} public class GestureView extends View implements OnTouchListener, OnGestureListener {GestureDetector mGestureDetector; public GestureView (Context context) {super (context); this. setOnTouchListener (this); mGestureDetector = new GestureDetector (this) ;}@ Overridepublic boolean onDown (MotionEvent e) {Log. I ("@ fred", "touch gesture: onDown"); return true ;}@ Overridepublic boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {if (e2.getX ()-e1.getX ()> 50) {Log. I ("@ fred", "touch gesture: onFling");} return true ;}@ Overridepublic void onLongPress (MotionEvent e) {Log. I ("@ fred", "touch gesture: onLongPress") ;}@ Overridepublic boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {Log. I ("@ fred", "touch gesture: onScroll"); return true ;}@ Overridepublic void onShowPress (MotionEvent e) {Log. I ("@ fred", "touch gesture: onShowPress") ;}@ Overridepublic boolean onSingleTapUp (MotionEvent e) {Log. I ("@ fred", "touch gesture: onSingleTapUp"); return true ;}@ Overridepublic boolean onTouch (View v, MotionEvent event) {// upload the MotionEvent event to GestureDetectorreturn mGestureDetector. onTouchEvent (event) ;}}for example, click the screen:

Related Article

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.