GestureDetector and gesturedetector

Source: Internet
Author: User

GestureDetector and gesturedetector

Because it is not easy to determine the real idea of user gestures in onTouchEvent, Android provides the GestureDetector detector to help us identify gestures. With the help of GestureDetector, you can identify several commonly used gesture events in most cases, such as click, long press, and flip pages. The following describes how to use GestureDetector:

Constructor: GestureDetector (Context context, OnGestureListener listener)
Listener Class Name: OnGestureListener
Set the listener method, first register the touch listener for the specified control, and then the GestureDetector takes over the touch event in the onTouch method:

private ScrollTextView tv_rough;  private GestureDetector mGesture;        tv_rough = (ScrollTextView) findViewById(R.id.tv_rough);      tv_rough.setOnTouchListener(this);      mGesture = new GestureDetector(this, this);        @Override  public boolean onTouch(View v, MotionEvent event) {      return mGesture.onTouchEvent(event);  }  

In addition, you can also override the onTouchEvent method in the current view or Activity. In this method, GestureDetector takes over the touch event.

Method to override the listener:
OnDown: called when the user presses
OnShowPress: called when pressed but not slide or released, usually used for highlighting when pressed
OnSingleTapUp: called when a user clicks it and then plays it again. It is usually used to click an event.
OnScroll: called during user sliding
OnLongPress
OnFling: called when a user quickly fetches a distance, usually used for page turning events

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.