Android View System (i) Views coordinate system

Source: Internet
Author: User

Preface

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

1.View Introduction

View is the base class for all Android controls, and ViewGroup is also inherited from view, and we will have an intuitive understanding of the following image:

We know that the hierarchy of the view helps us understand the view, and we see that the controls we use are inherited from view, and if we have a better grasp of the knowledge of the view, we will be more comfortable with the interface programming.

2.Android coordinate system

There are two coordinate systems in Android, the Android coordinate system and the view coordinate system, first we'll look at the Android coordinate system.
In Android, the top-left corner of the screen is the origin of the Android coordinate system, and the origin is the positive x-axis, and the origin downward is the y-axis positive direction.

The coordinates obtained by the motionevent provided by GETRAWX () and Getrawy () are the coordinates of the Android coordinate system.

3. View coordinate system

To understand the view coordinate system we just need to understand a picture to see:

view gets its own wide height
    • GetHeight (): Gets the view's own height
    • GetWidth (): Gets the view's own width
View own coordinates

You can get the distance from the view to its parent control (ViewGroup) by using the following method:

    • GetTop (): Gets the distance from the top edge of the view itself to the top of its parent layout
    • GetLeft (): Gets the distance from the left side of the view itself to its parent layout
    • GetRight (): Gets the distance from the right side of the view itself to the left side of its parent layout
    • Getbottom (): Gets the distance from the bottom of the view itself to the top edge of its parent layout
methods provided by Motionevent

We look at that dark blue point, assuming it's the point we're touching, and we know that the final click event will be handled by the Ontouchevent (Motionevent) method, whether it's a view or a viewgroup. Motionevent also provides a variety of ways to get focus coordinates:

    • GetX (): Gets the distance to the left of the Click event Distance control, which is the view coordinate
    • GetY (): Gets the distance from the top edge of the Click event Distance, which is the view coordinate
    • GETRAWX (): Gets the Click event Distance to the left of the entire screen, which is the absolute coordinates
    • Getrawy (): Gets the distance of the click event from the top edge of the entire screen, which is the absolute coordinate

Android View System (i) Views coordinate system

Related Article

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.