Touch in Android

Source: Internet
Author: User

 


The Touch processing in Android is very easy to use. Collect some information and share it as follows:

Android has two classes
Android. View. gesturedetector
Android. View. gesturedetector. simpleongesturelistener

1) create a class that inherits the simpleongesturelistener and hahagesturedetectorlistener class to implement the following Event Events.

Boolean ondoubletap (motionevent E)
Explanation: triggered when the second touch is down under double-click

Boolean ondoubletapevent (motionevent E)
Explanation: Double-click triggers both touch down and up, which 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 when it is up after sliding a little distance.

Void onlongpress (motionevent E)
Explanation: triggered when touch is down without moving

Boolean onscroll (motionevent E1, motionevent E2, float distancex, float distancey)
Explanation: It is triggered when sliding is reached.

Void onshowpress (motionevent E)
Explanation: triggered when touch is not sliding

Compared with ondown and onlongpress: ondown is triggered immediately as long as the touch is down.
After touchdown, onshowpress is triggered before onlongpress after a while without sliding.
Therefore, it does not slide after touchdown. ondown-> onshowpress-> onlongpress is triggered in this order.
)

Boolean onsingletapconfirmed (motionevent E)
Boolean onsingletapup (motionevent E)
Explanation: 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 slightly slower (do not slide) touchup:
Ondown-> onshowpress-> onsingletapup-> onsingletapconfirmed

2) create a gesturedetector object in view.
Constructor
Gesturedetector = new gesturedetector (New hahagesturedetectorlistener ());

Use the following code in ontouchevent of view to write your own code in the event 1 just now.
@ Override
Public Boolean ontouchevent (motionevent event ){
Gesturedetector. ontouchevent (event );
}

 

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.