Introduction to 025_01gesturedetector class and its usage

Source: Internet
Author: User

The Android SDK provides us with the Gesturedetector class, which allows us to identify a lot of gestures, mainly through his ontouchevent method, to complete the identification of different gestures.

Gesturedetector This class provides two interfaces and an internal class.
Interface: Ongesturelistener,ondoubletaplistener
Inner class: Simpleongesturelistener

The Simpleongesturelistener method is as follows:

Boolean onsingletapup (Motionevent e)

void Onlongpress (Motionevent e)

Boolean onscroll (Motionevent E1, motionevent E2, float Distancex, float distancey)

Boolean onfling (Motionevent E1, motionevent E2, float Velocityx, float velocityy)

void Onshowpress (Motionevent e)

Boolean Ondown (Motionevent e)

Boolean Ondoubletap (Motionevent e)

Boolean ondoubletapevent (Motionevent e)

Boolean onsingletapconfirmed (Motionevent e)

The following code implements left-and right-slip applications:

1  PackageCom.cskaoyan.mobilemanager;2 3  4 Importandroid.app.Activity;5 ImportAndroid.os.Bundle;6 ImportAndroid.view.GestureDetector;7 Importandroid.view.MotionEvent;8 ImportAndroid.view.View;9 ImportAndroid.view.GestureDetector.SimpleOnGestureListener;Ten  One  Public Abstract classSetupbaseactivityextendsActivity { A     Privategesturedetector Gesturedetector; -  - @Override the     protected voidonCreate (Bundle savedinstancestate) { -         //TODO auto-generated Method Stub -         Super. OnCreate (savedinstancestate); -Gesturedetector =NewGesturedetector ( This,NewMygesturedetectorlinstener ()); +  -     } +      A     classMygesturedetectorlinstenerextendssimpleongesturelistener{ at @Override -          Public Booleanonfling ( -Motionevent E1,//The point that starts to slide -Motionevent E2,//The point where the slide stops -                 floatVelocityx,//the speed of sliding in the x direction -                 floatVELOCITYY)//the speed of sliding in the Y direction in                 { -                 //TODO auto-generated Method Stub to                 floatStartX =e1.getx (); +                 floatStarty =e1.gety (); -                 floatEndX =e2.getx (); the                 floatEndy =e2.gety (); *              $                 if(Endx-startx >150 ) {Panax Notoginseng                     //swipe to previous page - previous (); the System.out +. println ("Setup1Activity.MyGestureDetectorLinstener.onFling () show Previous" ); A                 } the                 Else if(startx-endx>150) { + System.out -. println ("Setup1Activity.MyGestureDetectorLinstener.onFling () Show Next" ); $                    //swipe to the next page $ next (); -                 } -                 return Super. Onfling (E1, E2, Velocityx, velocityy); the                } -         Wuyi          the     } -      Wu @Override -      Public Booleanontouchevent (Motionevent event) { About         //TODO auto-generated Method Stub $          - gesturedetector.ontouchevent (event); -         return Super. Ontouchevent (event); -     } A      +      Public Abstract voidnext (); the      Public Abstract voidprevious (); -}

Then the abstraction of two methods next () and previous (), the need to jump through fling activity can inherit setupbaseactivity and implement both methods is OK.

Introduction to 025_01gesturedetector class and its usage

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.