The coordinate system of android View


View gets its own width and height

  • getHeight(): Get the height of the View itself
  • getWidth(): Get the width of the View itself

View's own coordinates

The distance from the View to its parent control (ViewGroup) can be obtained by the following methods:

  • getTop(): Get the distance from the top edge of the View itself to the top edge of its parent layout
  • getLeft(): Get the distance from the left side of the View itself to the left side of its parent layout
  • getRight(): Get the distance from the right side of the View itself to the left side of its parent layout
  • getBottom(): Get the distance from the bottom edge of the View itself to the top edge of its parent layout

Methods provided by MotionEvent

Let's look at the dark blue point in the picture above. Assuming that it is the point we touch, we know that whether it is a View or a ViewGroup, the final click event will be handled by the onTouchEvent (MotionEvent event) method. MotionEvent also provides various methods to obtain focus coordinates. method:

  • getX(): Get the distance of the click event from the left side of the control, that is, the view coordinates
  • getY(): Get the distance from the click event to the top edge of the control, that is, the view coordinates
  • getRawX(): Get the distance of the click event from the left side of the entire screen, that is, absolute coordinates
  • getRawY(): Get the distance of the click event from the top edge of the entire screen, that is, absolute coordinates
  


Tribute to the author https://blog.csdn.net/itachi85/article/details/50708391

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325210675&siteId=291194637