Android screen (View) coordinate system

Source: Internet
Author: User

first clarify the coordinate system in Android: the upper-left corner of the screen is the coordinate system origin (0,0), the origin point extends to the right of the x-axis positive direction, the origin of the downward extension of the y-axis positive direction.
first, the coordinates of the view
It is important to note that the coordinates of the view are relative to the parent container, including: GetTop (), Getbottom (), GetLeft (), GetRight (). Take GetTop as an example, the function source code is:
/**
* Top position of this view relative to its parent.
* Relative to the top position of the parent control, in pixels, that is, the distance from the head to the parent control
* @return The top of this view, in pixels.
*/ 
@ViewDebug. Capturedviewproperty
Public final int getTop () {
return mtop;
}   
Figure 1:




Figure 2:


1. Left position of view view.getleft ()
2. Right position of view view.getright ()
3, the top position of the view view.gettop ();
4, the view bottom position view.getbottom ();
5, view width view.getwidth ();
6. View Height view.getheight ()
Second, Motionevent class Getrowx () and GetX ()
1, Event.getrowx (): The x-coordinate of the touch point relative to the screen Origin
2, Event.getx (): The x-coordinate of the touch point relative to the origin of its component
Diagram

Android screen (View) coordinate system

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.