Consider the view as a rectangle, representing the distance from the left side of the view, the top, the right, and the bottom distance of his parent component.
GetRight () =getleft () + getwidth ()
Getbottom () = GetTop () + getheight ()
One, the coordinate study one
Each view group contains a width and height (layout_width and Layout_height), and each view must define them. Many layoutparams also include optional margin (blank) and border (boundary).
You can use exact values to specify the width and height, although you may use it very rarely. More commonly, you set the size of the view object to be appropriate for its contents, or to fill in as many of its parent objects as possible (corresponding to wrap_content and fill_parent respectively). Acceptable length units are in the available resources documentation.
Layout Position
The geometric properties of the view are the geometric properties of the rectangle in which it is located. The position of a view is represented by a pair of left and top coordinates, and two lengths are expressed in width and height. The units of position and length are pixels.
The location of a view can be obtained by calling GetLeft () and GetTop (). The two methods return a position relative to their parent element, for example, if GetLeft () returns 20, the distance between it and the sitting boundary of its immediate parent element is 20 pixels.
In addition, there are some methods that exist just for the convenience of writing programs, such as GetRight () and Getbottom (). GetRight () and GetLeft () +getwidth () have the same effect.
Size, Padding and Margins
The size of a view is described using width and height. A view actually has two sets of height and width values.
The first group becomes the measuring width and the measuring height. These lengths define the size of a view that you want in its parent view. Measurement lengths can be obtained using getmesuredwidth () and Getmeasuredheight ().
The second group is width and height, and is sometimes drawn as the width and height of the drawing. These lengths define the actual size of the view on the screen. These values may differ from the measurement length. They can be obtained through getwidth () and GetHeight ().
To measure its length, a view takes its padding into account. Padding uses the image to indicate that the padding can be set up or down in all directions. Padding can be used to create a displacement of the view. For example, a 2-pixel left padding will shift the view to the right by 2 pixels. Can be set using Setpadding (Int,int,int,int), which is obtained by Getpaddingleft (), Getpaddingtop (), Getpaddingright (), and Getpaddingbottom ().
Although a view can define a padding, it does not support margin. View group supports margin.
If you implement the Ontouchlistener interface in one of your activity, you need to rewrite the Ontouch (View view,motionevent Event) method, and Getrawx () and Getrawy () get a relative screen position. GetX () and gety () always get the touch position coordinates of the view (these two values do not exceed the length and width of the view).
If you rewrite the activity's Ontouchevent (Motionevent event), this time you get the coordinates of the screen click position. Event.getx () Gets the same value as EVENT.GETRAWX (), and Event.gety () is the same as the value obtained by Event.getrawy (), but also gets the coordinate position when the title bar is touched, but the coordinate position when the status bar is touched is not available. (Note: The activity has two segments width: one is the status bar, one is the title bar, each width is 25 pixels)
Understanding View.getleft () GetTop () GetRight () and Getbottom ()
Title, in fact, the view is a rectangle that represents the distance from the left side of a view, the top, the right, and the bottom distance from his parent component.
GetRight () =getleft () + getwidth (). Getbottom () = GetTop () + getheight (); It's important for beginners to figure out
In fact, I didn't quite understand it before, I was also educated.
Android coordinates and wide height study getleft () GetTop () GetRight () and Getbottom ()