Android Screen Swipe Event

Source: Internet
Author: User

http://blog.csdn.net/iamfafa/article/details/6316062

There are two classes in Android

Android.view.GestureDetector

Android.view.GestureDetector.SimpleOnGestureListener

(another android.widget.Gallery seems to be the ongesturelistener of the Bull X)

1) Create a new class to inherit Simpleongesturelistener,hahagesturedetectorlistener

The following event events can be implemented.

Boolean Ondoubletap (Motionevent e)

Explanation: triggered when double click on second touch down

Boolean ondoubletapevent (Motionevent e)

Explanation: The second touch down and up of double-click are triggered and can be distinguished by e.getaction ().

Boolean Ondown (Motionevent e)

Explanation: Triggered when Touch is down

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

Explanation: Touch is triggered after sliding a little distance up.

void Onlongpress (Motionevent e)

Explanation: Touch does not move until touch down is triggered

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

Explanation: Touch triggered when sliding.

void Onshowpress (Motionevent e)

Explanation: Touch has not yet slid when triggered

(Compare with Ondown,onlongpress

Ondown as long as touch down must be triggered immediately.

and touchdown after a while not sliding first triggered onshowpress and then onlongpress.

So after touchdown has not slipped, ondown->onshowpress->onlongpress this sequence trigger.

)

Boolean onsingletapconfirmed (Motionevent e)

Boolean onsingletapup (Motionevent e)

Explanation: Both of these functions are not sliding after touch down (onscroll), not long pressed (onlongpress), and then triggered when touchup.

Click on the very fast (do not swipe) Touchup:

Ondown->onsingletapup->onsingletapconfirmed

Click on a slightly slower (not sliding) Touchup:

Ondown->onshowpress->onsingletapup->onsingletapconfirmed

2) Create a new Gesturedetector object in the view.

In the constructor gesturedetector = new Gesturedetector (new Hahagesturedetectorlistener ());

And then in the ontouchevent of the view, the following, you can write your own code in the event that was just 1.

@Override

public boolean ontouchevent (Motionevent event) {

Gesturedetector.ontouchevent (event);

}

However, the depressed is Simpleongesturelistener did not provide onup (), but also in the view of the

Ontouchevent's

Case MOTIONEVENT.ACTION_UP:

To write the corresponding code.

Android Screen Swipe Event

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.