The difference between getx () and GETRAWX () in Motionevent

Source: Internet
Author: User
Tags gety

http://blog.csdn.net/ztp800201/article/details/17218067

     Public classResextendsActivityImplementsView.ontouchlistener {Button btn=NULL; intx = 0; inty = 0; intRAWX = 0; intRawy = 0; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.main); BTN=(Button) Findviewbyid (R.id.button); Btn.setontouchlistener ( This); }                     Public BooleanOnTouch (view view, Motionevent event) {intEventaction =event.getaction (); Switch(eventaction) { CaseMotionevent.action_down: Break;  Casemotionevent.action_move:x= (int) Event.getx (); Y= (int) event.gety (); RAWX= (int) event.getrawx (); Rawy= (int) Event.getrawy (); LOG.D ("DEBUG", "getx=" + x + "gety=" + y + "n" + "getrawx=" +rawx+ "getrawy=" + Rawy + "n");  Break;  Casemotionevent.action_up: Break; }                return false; }        }    


When you touch a button, x, Y is relative to the upper-left point of the button (the control itself).
The Rawx,rawy is always relative to the screen position.
Know:
GETRAWX: The coordinates of the touch point relative to the screen
getx: The coordinates of the touch point relative to the button
gettop: The upper-left corner of the button is
getleft: The x-coordinate of the upper-left corner of the button relative to the parent view (linerlayout)

GetX () is the x-coordinate of the widget relative to its upper-left corner, and Getrawx () is the x-coordinate value relative to the upper-left corner of the screen (note: The upper-left corner of the screen is the upper-left corner of the phone screen, regardless of whether the activity has titlebar or full screen), GetY (), Getrawy () The same reason

The difference between getx () and GETRAWX () in Motionevent

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.