Android Gesture Monitor (Gesturedetector Class)

Source: Internet
Author: User



public class Gesturetest extends Activity implements Onclicklistener, Ongesturelistener {//define gesture Detector instance Gesturedetector detector; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity10_layout);//create gesture Detector detector = new Gesturedetector (this);} Handing the touch event on the activity to Gesturedetector processing @overridepublic boolean ontouchevent (motionevent me) {return Detector.ontouchevent (Me);} @Overridepublic boolean Ondown (Motionevent arg0) {Toast.maketext (this, "pressing", Toast.length_long). Show (); return false ;} @Overridepublic boolean onfling (motionevent E1, motionevent E2, float Velocityx, float velocityy) {Toast.maketext (this, " Throwing ", Toast.length_long). Show (); return false;} @Overridepublic void Onlongpress (Motionevent e) {Toast.maketext (this, "long press", Toast.length_long). Show (); @Overridepublic boolean onscroll (motionevent E1, motionevent E2, float Distancex, float distancey) {Toast.maketext (this, "Sliding", Toast.length_long). Show (); return False;} @Overridepublic void Onshowpress (Motionevent e) {Toast.maketext (this, "holding", Toast.length_long). Show (); @Overridepublic Boolean onsingletapup (Motionevent e) {Toast.maketext (this, "lifting", Toast.length_long). Show (); return false;} @Overridepublic void OnClick (View arg0) {}}


where the onfling () parameter has the following meanings:

E1: Move event at start of gesture
e2: Move event of the current gesture point
velocityx: pixels moving X-axis per second
velocityy: Pixels moved in Y-axis per second


where the onscroll () parameter has the following meanings:

Distancex: equals the x value of E1 minus the X value of E2, and the result is signed.

Distancey: equals the Y value of E1 minus the Y value of E2 and evaluates to a sign.



Android Gesture Monitor (Gesturedetector Class)

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.