Android View system (I) View Coordinate System

Source: Internet
Author: User

Android View system (I) View Coordinate System
Preface

The Android View system is the core of interface programming. It is no less important than the four major Android components, in this series, I will talk about the View coordinate system, View slide, View event distribution, and other articles to introduce the Android View system gradually.

1. View Introduction

View is the base class of all Android controls, and ViewGroup is also inherited from View. The following figure gives us an intuitive understanding:
Vc7Sw8ezo9PDtcTV4tCpv9i8/release + samples + G4/LzTtcS1w9DE06bK1qGjPC9wPg0KPGgzIGlkPQ = "2android Coordinate System">2. Android Coordinate System

Android has two coordinate systems: the Android coordinate system and the view coordinate system. First, let's take a look at the Android coordinate system.
In Android, the vertex in the upper left corner of the screen is used as the origin of the Android coordinate system. The origin is in the positive direction of the X axis to the right, and the downward direction of the origin is in the positive direction of the Y axis.

The getRawX () and getRawY () coordinates provided by MotionEvent described below are the coordinates of the Android coordinate system.

3. View Coordinate System

To understand the view coordinate system, you only need to understand a graph:

View to get its own width and heightGetHeight (): Get the View height getWidth (): Get the View width View coordinates

You can obtain the distance from the View to its parent widget (ViewGroup) by using the following method:

GetTop (): Get the distance from the top edge of the View to the top edge of its parent layout getLeft (): Get the distance from the left side of the View to the left side of its parent layout getRight (): get the distance from the right side of the View to the left side of its parent layout getBottom (): Get the distance from the bottom side of the View to the top side of its parent Layout MotionEvent Method

Let's take a look at the dark blue point. Suppose it's our touch point. We know that whether it's 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 focal point coordinates:

GetX (): Get the distance from the click event to the left of the control, that is, the view coordinate getY (): Get the distance from the click event to the top side of the control, that is, the view coordinate getRawX (): get the distance from the click event to the left of the screen, that is, the absolute coordinate getRawY (): Get the distance from the click event to the top side of the screen, that is, the absolute Coordinate

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.