android view源码(翻译头部2)
ID
Views may have an integer id associated with them.
视图可能具有与之关联的整数ID。
These ids are typically assigned in the layout XML files, and are used to find specific views within the view tree.
这些ID通常是在布局XML文件中分配的,用于在视图树中查找特定的视图。
View IDs need not be unique throughout the tree, but it is good practice to ensure that they are at least unique within the part of the tree you are searching.
视图ID不必在整个树中都是唯一的,但是最好的做法是确保它们在您要搜索的树的一部分中至少是唯一的。
Position
The geometry of a view is that of a rectangle.
视图的几何形状是矩形的几何形状
A view has a location, expressed as a pair of <em>left</em> and <em>top</em> coordinates, and two dimensions, expressed as a width and a height.
视图的位置表示为一对左坐标和顶坐标,两个维度表示为宽度和高度
The unit for location and dimensions is the pixel.
位置和尺寸的单位是像素。
It is possible to retrieve the location of a view by invoking the methods {@link #getLeft()} and {@link #getTop()}.
可以通过调用方法{@link #getLeft()}和{@link #getTop()}来检索视图的位置
The former returns the left, or X,coordinate of the rectangle representing the view. The latter returns the top, or Y, coordinate of the rectangle representing the view.
前者返回代表视图的矩形的左坐标或X坐标,后者返回代表视图的矩形的顶部或Y坐标。
These methods both return the location of the view relative to its parent.
这些方法都返回视图相对于其父视图的位置。
For instance,when getLeft() returns 20, that means the view is located 20 pixels to the right of the left edge of its direct parent.
例如,当getLeft()返回20时,这意味着该视图位于其直接父级的左边缘的右侧20个像素处
In addition, several convenience methods are offered to avoid unnecessary computations, namely {@link #getRight()} and {@link #getBottom()}.
此外,还提供了几种便捷方法来避免不必要的计算,即{@link #getRight()}和{@link #getBottom()}
These methods return the coordinates of the right and bottom edges of the rectangle representing the view.
这些方法返回代表视图的矩形的右边缘和下边缘的坐标
For instance, calling {@link #getRight()} is similar to the following computation: <code>getLeft() + getWidth()</code> (see <a href="#SizePaddingMargins">Size</a> for more information about the width.)
例如,调用{@link #getRight()}类似于以下计算:getLeft()+ getWidth()
(前面提到视图的位置表示为一对左坐标和顶坐标,所以view的getLeft,getRight都是距离父级的左侧距离,getBottom,getTop都是距离父级的顶侧距离)
SizePaddingMargins
The size of a view is expressed with a width and a height.
视图的大小用宽度和高度表示。
A view actually possess two pairs of width and height values.
一个视图实际上具有两对宽度和高度值。
The first pair is known as <em>measured width</em> and<em>measured height</em>.
第一对被称为``测量宽度''和``测量高度''。
These dimensions define how big a view wants to be within its parent (see <a href="#Layout">Layout</a> for more details.)
这些尺寸定义了视图在其父视图中的大小(有关更多详细信息,请参见布局)。
The measured dimensions can be obtained by calling {@link #getMeasuredWidth()}and {@link #getMeasuredHeight()}.
可以通过调用{@link #getMeasuredWidth()}和{@link #getMeasuredHeight()}获得测量尺寸。
The second pair is simply known as <em>width</em> and <em>height</em>, or sometimes <em>drawing width</em> and <em>drawing height</em>.
第二对简称为宽度和高度,有时也称为绘图宽度和绘图高度。
These dimensions define the actual size of the view on screen, at drawing time and after layout.
这些尺寸定义了屏幕上,绘制时和布局后视图的实际尺寸。
These values may, but do not have to, be different from the measured width and height.
这些值可以但不必与测量的宽度和高度不同。
The width and height can be obtained by calling{@link #getWidth()} and {@link #getHeight()}.
宽度和高度可以通过调用{@link #getWidth()}和{@link #getHeight()}获得。
To measure its dimensions, a view takes into account its padding.
要测量其尺寸,视图应考虑其填充(padding)
The padding is expressed in pixels for the left, top, right and bottom parts of the view.
对于视图的左,顶部,右侧和底部,填充(padding)用像素表示。
Padding can be used to offset the content of the view by a specific amount of pixels.
填充(padding)可用于将视图内容偏移特定数量的像素
For instance, a left padding of 2 will push the view's content by 2 pixels to the right of the left edge.
例如,向左填充2会将视图的内容向左边缘的右侧推2个像素
Padding can be set using the {@link #setPadding(int, int, int, int)} or {@link #setPaddingRelative(int, int, int, int)} method and queried by calling {@link #getPaddingLeft()}, {@link #getPaddingTop()},
{@link #getPaddingRight()}, {@link #getPaddingBottom()}, {@link #getPaddingStart()},{@link #getPaddingEnd()}.
可以使用{@link #setPadding(int,int,int,int)}或{@link #setPaddingRelative(int,int,int,int)}方法来设置填充,并通过调用{@link #getPaddingLeft()}进行查询
Even though a view can define a padding, it does not provide any support for margins.
即使视图可以定义填充,它也不能为边距提供任何支持。
However, view groups provide such a support.
但是,视图组提供了这种支持。
Refer to{@link android.view.ViewGroup} and {@link android.view.ViewGroup.MarginLayoutParams} for further information.
有关更多信息,请参考{@link android.view.ViewGroup}和{@link android.view.ViewGroup.MarginLayoutParams}。
关注本人公众号获取更多干货.