Android slide gesture

Source: Internet
Author: User

Android slide gesture

Usage: First let the specified Activity implement Android. view. OnGestureListener, then add onTouchListener on The View where you need to call GestureDetector, and then setLongClickable (true.

For example:

CustomView. setOnTouchListner (xxxListener );

CustomView. setLongClickable (true );

 

Then you can set the expected gesture in the onFling method.

 

Description of onFling method parameters:

OnFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)

Official explanation:

 

Notified of a fling event when it occurs with the initial on downMotionEventAnd the matching upMotionEvent. The calculated velocity is supplied along the x and y axis in pixels per second.

Specified:OnFling (...) in OnGestureListener Parameters: E1The first down motion event that started the fling. E2The move motion event that triggered the current onFling. VelocityXThe velocity of this fling measured in pixels per second along the x axis. VelocityYThe velocity of this fling measured in pixels per second along the y axis. Returns: true if the event is consumed, else false roughly means:

E1 indicates an event triggered instantly when the finger is pressed,

E2 indicates the event triggered when the finger is not started and moved

The remaining two parameters roughly mean the number of pixel points moving in the x and y directions per second.

Therefore, you can use e1 and e2 to create conditions for gesture judgment.

Simple left and right sliding gesture code:

@Overridepublic boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) {// TODO Auto-generated method stubtoif (e1.getX() > e2.getX()) {Log.i(msg, <<<<<<<<<);} else {Log.i(msg, >>>>>>>>>);}Toast.makeText(this, Fling, 0).show();return false;}

 

 

 

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.