[Excerpt] Use gesturedector

Source: Internet
Author: User
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 must be triggered immediately as long as touch 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

With so many response methods, we can more easily respond to user touch operations and correspond to various actions. How to use this class is actually very simple. Create a gesturedetector object in view. Constructor
Gesturedetector = new gesturedetector (New selfgesturedetectorlistener ());

You can use the following in ontouchevent of the view to write your own data in the gesturedetector event.Code.
@ Override
Public Boolean ontouchevent (motionevent event ){
Gesturedetector. ontouchevent (event );
}

For the ontouchevent method above, we can directly determine the motionevent type. For gesture movement, we only need to capture action_move. Through the motionevent E1, motionevent E2, float distancex, float distancey can be used to obtain operation changes.

For example, distancex> 0 moves to the right, distancex <0 moves to the left, distancey> 0 scrolls Up, And distancey <0 scrolls down. During the test, we can encapsulate this class. When each method is triggered, logcat is used to print the action and X, and Y coordinates to understand the actual situation and perform more in-depth and complex gesture detection, the android development network will be written next time.

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.