Android Android to determine whether to swipe

Source: Internet
Author: User

(Transferred from: http://blog.csdn.net/angle_rupert/article/details/6255522)

Statement:

1     float x_temp01 = 0.0f; 2     float y_temp01 = 0.0f; 3     float x_temp02 = 0.0f; 4     float

Ontouchevent method for overriding activity:

1 @Override2      Public Booleanontouchevent (motionevent event)3     {4         //get current coordinates5             floatx =event.getx ();6             floaty =event.gety ();7             8             Switch(Event.getaction ())9             {Ten                      CaseMotionevent.action_down: One                     { AX_TEMP01 =x; -Y_TEMP01 =y; -                     } the                      Break; -                      Casemotionevent.action_up: -                     { -X_TEMP02 =x; +Y_TEMP02 =y; -                          +                         if(X_temp01!=0 && y_temp01!=0)// A                         { at                                 //Compare X_TEMP01 and X_temp02 -                                 //X_TEMP01>X_TEMP02//left -                                 //X_TEMP01==X_TEMP02//In a vertical direction or not moving . -                                 //X_TEMP01<X_TEMP02//Right -                                  -                                 if(X_TEMP01&GT;X_TEMP02)//left in                                 { -                                         //moved the X_TEMP01-X_TEMP02 to                                 } +                                  -                                 if(X_TEMP01&LT;X_TEMP02)//Right the                                 { *                                         //moved the X_TEMP02-X_TEMP01 $                                 }Panax Notoginseng                         } -                     } the                      Break; +                      CaseMotionevent.action_move: A                     { the                              +                     } -                      Break; $  $             } -             return Super. Ontouchevent (event); -}

Note that the test is feasible, simple and useful;

Change your own decision whether to swipe:

1          CaseMotionevent.action_down: {2Ismove =false;3downx=x;4downy=y;5                          Break;6                      }7          Casemotionevent.action_up: {8UpX =x;9upy=y;Ten             if((upx-downx!=0) | | (upy-downy!=0)) OneIsmove=true; A             Else -Ismove=false; -                          Break; the}

Android Android to determine whether to swipe

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.