Android briefly describes the Motionevent in touch events

Source: Internet
Author: User

There is a motionevent parameter in the TouchEvent event, so here's a brief introduction to some of the implications of its properties and how to use it

Generally, a single finger operation is generally as follows:

Switch (event.getaction ()) {//First touch point case motionevent.action_down:  //press = 0<span style= "White-space:pre" > float x = Event.getx (); </span>break;case motionevent.action_move:  //move = 2break;case motionevent.action_up:    //lift = 1break;}

When multi-touch:

The following properties appear at API level 5 and API Level 8 is obsolete.

Motionevent.action_pointer_1_down
Motionevent.action_pointer_2_down
Motionevent.action_pointer_3_down
Motionevent.action_pointer_1_up
Motionevent.action_pointer_2_up
Motionevent.action_pointer_3_up

API Level 8 is 2.2 after: Motionevent.action_pointer_downmotionevent.action_pointer_up


The following tests found that when a single touch

Switch (event.getaction ()) {//case Motionevent.action_down://press = 0//SYSTEM.OUT.PRINTLN ("ontouchevent");//break;// Case motionevent.action_move://move = 2////break;//case motionevent.action_up://lift = 1////break;case MotionEvent.ACTION _pointer_down://not the first touch point press  = 5system.out.println ("Action_pointer_down"); Break;case Motionevent.action_pointer _UP://Not first touch point lifted   = 6system.out.println ("action_pointer_up"); break;default:break;}
motionevent.action_pointer_downmotionevent.action_pointer_upNot executed


The second point takes the x, Y coordinate values

float x2 = event.getx (Event.getactionindex ());//action index starts from 0 to pointer count-1 end float y2 = event.gety (event.getactio NIndex ());//The y-coordinate of the touch point of an index relative to the current view Event.getpointercount (); Number of touch points



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.