Location of Android View

Source: Internet
Author: User

Introduction

  Today we introduce the positioning of the Android coordinate system and the view, and of course the sliding related topics of the view. Let's start with the introduction.

The basics of view

View is the base class for all controls in Android, both TextView, Button, Relativelayout, and ListView, which are common base classes are view. View is an abstraction of an interface layer control that represents a control. ViewGroup translation comes from the meaning of a control group, ViewGroup can contain multiple child controls, a set of view. ViewGroup also inherits from view in Android, which means that the view itself can be a single control or a set of controls consisting of multiple controls.

Location parameters for view

The position parameter of the view is determined primarily by its four vertices, which correspond to the four properties of the view: Top, left, bottom, right. Top of which is the upper left corner of the vertical axis, left is the upper corner of the horizontal axis, bottom is the bottom right corner of the vertical axis, right is the lower corner of the horizontal axis. It is important to note that these coordinates are relative to the view's parent container, which is a relative coordinate . :

This diagram is very clear about the view we have just described the relative position of the content, we can easily know the width of the view is Right-left value, of course, height is bottom-top. At the same time we can get left, top, right, and bottom values through GetLeft, GetTop, GetRight, Getbottom.

  Note the point:

Starting with Android 3.0, view added x, y, Translationx, Translationy. where x and y are the coordinates of the upper-left corner of the view, Translationx and Translationy are the offsets of the upper-left corner of the view relative to the parent container. These values are also relative to the parent container's coordinates, and the Translationx and translationy default values are 0. The conversion relationships of these parameters are as follows:

1, X=left+translationx;

2, Y=top+translationy;

  It is important to note that when you move the view, top and left represent the position information of the original upper right corner, and its value does not change. At this point, the changes are X, Y, Translationx, Translationy.

  1. View.gettranslationx calculates the offset of the view. The initial value is 0, the left offset value is negative, and the right offset value is positive.

2, view.getx equivalent to the view distance from the left edge of the parent container, equal to Getleft+gettranslationx.

We still look at the picture:

We see that the picture on the left is in the initial case. At this time Translationx and Translationy are all 0. In the second picture we move the view to the right x position, and we know from the above analysis that the value of left and top has not changed. The change is Translationx.

Talk more about RAWX and SCROLLX.  

  RAWX is the absolute coordinate, is relative to the upper left corner of the screen, the view itself is not getrawx method, this method is generally used in motionevent objects.

SCROLLX refers to the distance between the left edge of the view and the left edge of the view content in the horizontal direction of the view during the sliding process (note the difference from the Translationx, Translationx refers to the movement of the view itself, SCROLLX is the content movement of the view, which means that the view's Scrollto or Scrollby method is called, and the viewitself does not move and only the contents of the view are moved . Look at the picture:

Location of Android View

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.