Simple ways to use Android swipe gestures

Source: Internet
Author: User

Usage: First let the specified activity implement Android.view.OnGestureListener, and then add Ontouchlistener on the view you need to call Gesturedetector, Setlongclickable (true) can be followed.

Such as:

Customview.setontouchlistner (Xxxlistener);

Customview.setlongclickable (TRUE);


You can then set the gesture you want in the Onfling method.


Onfling Method Parameter Explanation:

Onfling (motionevent E1, motionevent E2, float velocityx,float velocityy)

Official explanation:

Notified of a fling event when it occurs with the initial in down and the MotionEvent matching up MotionEvent . The calculated velocity is supplied along, the X and Y axis in pixels per second.

Specified by:Onfling (...) inongesturelistener
Parameters:
E1 The first down motion event, that started the fling.
E2 The move motion event triggered the current onfling.
Velocityx The velocity of this fling measured in pixels per second along the X axis.
velocityy The velocity of this fling measured in pixels per second along the Y axis.
Returns:
True if the event is consumed, else false
General meaning:

E1 represents an event that is triggered by the moment the finger is pressed,

E2 represents an event triggered when the finger is not bouncing and moving

The remaining two parameters roughly mean the number of pixels per second moving in the X, y direction.

So, by E1 and E2, you can create a judging condition for gestures.

Simple left and right swipe gesture code:

@Overridepublic boolean onfling (motionevent E1, motionevent E2, float velocityx,float velocityy) {//TODO auto-generated m Ethod stubtoif (E1.getx () > E2.getx ()) {log.i ("msg", "<<<<<<<<<");} else {log.i ("msg", "& Gt;>>>>>>>> ");} Toast.maketext (This, "Fling", 0). Show (); return false;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Simple ways to use Android swipe gestures

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.