/**
* LayoutParams are used by views to telltheir parents how they want to be
* laid out. See
* {@linkandroid.R.styleable#ViewGroup_Layout ViewGroup Layout Attributes}
* for a list of all child view attributesthat this class supports.
*
*
* The base LayoutParams class justdescribes how big the view wants to be
* for both width and height. For eachdimension, it can specify one of:
*
* FILL_PARENT (renamed MATCH_PARENTin API Level 8 and higher), which
* means that the view wants to be as bigas its parent (minus padding)
* WRAP_CONTENT, which means thatthe view wants to be just big enough
* to enclose its content (plus padding)
* an exact number
*
* There are subclasses of LayoutParams fordifferent subclasses of
* ViewGroup. For example, AbsoluteLayouthas its own subclass of
* LayoutParams which adds an X and Y value.
*
* * Developer Guides * For more information aboutcreating user interface layouts, read the * * guide.
*
* @attr refandroid.R.styleable#ViewGroup_Layout_layout_height
* @attr refandroid.R.styleable#ViewGroup_Layout_layout_width
*/
/*ViewGroup.LayoutParames
*
* LayoutParams被View用于告诉它的父控件它要多大的空间
* 看android.R.styleable.ViewGroup_Layout ViewGroup布局属性列表,这个列表是这个类支持的所有子控件属性
* 基类LayoutParams仅仅描述View想要多大宽高的空间,每个尺寸可以指定以下其中一种:
* 1.FILL_PARENT(重命名为)MATCH_PARENT在API8或更高,这个类型说明view想要和父控件(减去padding)一样大
* 2.WRAP_CONTENT,说明view只想要仅仅足够大的空间贴近它(加上padding)内容
* 3.精确的数字
*
* 有一些LayoutParams的子类用于ViewGroup的各个子类。例如:AbsoluteLayout有它自己的LayoutParams子类,这个类增加了X和Y值
*/
public static class LayoutParams {
/**
* Special value for the height orwidth requested by a View.
* FILL_PARENT means that the viewwants to be as big as its parent,
* minus the parent's padding, if any.This value is deprecated
* starting in API Level 8 and replacedby {@link#MATCH_PARENT}.
*/
/* 特殊值用于view请求宽高
* 这个值说明了view想要和它的父控件一样大(如果父控件有padding属性,则父控件减去padding后)
* 这个值从API8开始被弃用,被MATCH_PARENT替代
*/
@SuppressWarnings({"UnusedDeclaration"})
@Deprecated
public static final int FILL_PARENT = -1;
/**
* Special value for the height orwidth requested by a View.
* MATCH_PARENT means that the viewwants to be as big as its parent,
* minus the parent's padding, if any.Introduced in API Level 8.
*/
/* 特殊值用于view请求宽高
* 这个值说明了view想要和它的父控件一样大(如果父控件有padding属性,则父控件减去padding后)
* 这个值从API8开始被介绍
*/
public static final int MATCH_PARENT = -1;
/**
* Special value for the height orwidth requested by a View.
* WRAP_CONTENT means that the view wants tobe just large enough to fit
* its own internal content, taking itsown padding into account.
*/
/* 特殊值用于view请求宽高
* 这个值说明了view仅仅想要足够大去适应它内部的内容,这个大小是已把padding计算进去的
*/
public static final int WRAP_CONTENT = -2;
/**
* Information about how wide the viewwants to be. Can be one of the
* constants FILL_PARENT (replaced byMATCH_PARENT ,
* in API Level 8) or WRAP_CONTENT. oran exact size.
*/
/* view的宽高信息
* 是以下这些常量中的一种
* MATCH_PARENT,WRAP_CONTENT,精确尺寸
*/
@ViewDebug.ExportedProperty(category ="layout", mapping = {
@ViewDebug.IntToString(from =MATCH_PARENT, to = "MATCH_PARENT"),
@ViewDebug.IntToString(from =WRAP_CONTENT, to = "WRAP_CONTENT")
})
public int width;
/**
* Information about how tall the viewwants to be. Can be one of the
* constants FILL_PARENT (replaced byMATCH_PARENT ,
* in API Level 8) or WRAP_CONTENT. oran exact size.
*/
@ViewDebug.ExportedProperty(category ="layout", mapping = {
@ViewDebug.IntToString(from =MATCH_PARENT, to = "MATCH_PARENT"),
@ViewDebug.IntToString(from =WRAP_CONTENT, to = "WRAP_CONTENT")
})
public int height;
/**
* Used to animate layouts.
*/
/*用于给布局增加动画
*/
publicLayoutAnimationController.AnimationParameterslayoutAnimationParameters;
/**
* Creates a new set of layoutparameters. The values are extracted from
* the supplied attributes set andcontext. The XML attributes mapped
* to this set of layout parametersare:
*
*
*
* {@link#WRAP_CONTENT},or{@link #FILL_PARENT} (replaced by
* {@link#MATCH_PARENT}in API Level 8)
*
* {@link#WRAP_CONTENT},or{@link #FILL_PARENT} (replaced by
* {@link#MATCH_PARENT}in API Level 8)
*
*
* @param c the application environment
* @param attrs the set of attributes fromwhich to extract the layout
* parameters' values
*/
/* 创建一个新的布局参数集合
* 这些值是从支持的属性集合上下文中提取出来的
* XML属性映射到布局参数集合的是:
* layout_width
* layout_height
*/
public LayoutParams(Context c,AttributeSet attrs) {
TypedArray a =c.obtainStyledAttributes(attrs, R.styleable.ViewGroup_Layout);
setBaseAttributes(a,
R.styleable.ViewGroup_Layout_layout_width,
R.styleable.ViewGroup_Layout_layout_height);
a.recycle();
}
/**
* Creates a new set of layoutparameters with the specified width
* and height.
*
* @param width the width, either{@link #WRAP_CONTENT},
* {@link #FILL_PARENT} (replaced by{@link #MATCH_PARENT} in
* API Level 8), or a fixed size in pixels
* @param height the height, either{@link #WRAP_CONTENT},
* {@link #FILL_PARENT} (replaced by{@link #MATCH_PARENT} in
* API Level 8), or a fixed size in pixels
*/
/* 创建一个新的布局参数集合
* 这些值是从支持的属性集合上下文中提取出来的
* @param width 宽度,如果是精确的值,那么单位是像素
* @param height 高度
*/
public LayoutParams(int width,int height) {
this.width = width;
this.height = height;
}
/**
* Copy constructor. Clones the widthand height values of the source.
*
* @param source The layout params to copyfrom.
*/
/* 复制构造器,克隆源LayoutParams的宽高值
* @param source 源LayoutParams
*/
public LayoutParams(LayoutParams source) {
this.width = source.width;
this.height = source.height;
}
/**
* Used internally byMarginLayoutParams.
* @hide
*/
/* 被内部MarginLayoutParams使用
*/
LayoutParams() {
}
/**
* Extracts the layout parameters fromthe supplied attributes.
*
* @param a the style attributes to extractthe parameters from
* @param widthAttr the identifier of thewidth attribute
* @param heightAttr the identifier of theheight attribute
*/
/* 从支持的属性中取得布局参数
* @param a 样式属性,用于取出参数
* @param widthAttr 宽度属性的识别标记
* @param heightAttr
*/
protected void setBaseAttributes(TypedArray a, int widthAttr,int heightAttr) {
width = a.getLayoutDimension(widthAttr,"layout_width");
height = a.getLayoutDimension(heightAttr,"layout_height");
}
/**
* Resolve layout parameters dependingon the layout direction. Subclasses that care about
* layoutDirection changes shouldoverride this method. The default implementation does
* nothing.
*
* @param layoutDirection the direction ofthe layout
*
* {@link View#LAYOUT_DIRECTION_LTR}
* {@link View#LAYOUT_DIRECTION_RTL}
*/
/* 根据布局方向解决布局参数,如果子类关心布局方向的改变,应该重写这个方法,默认实现是空的。
* @param layoutDirection
*/
public void resolveLayoutDirection(int layoutDirection) {
}
/**
* Returns a String representation ofthis set of layout parameters.
*
* @param output the String to prepend tothe internal representation
* @return a String with the followingformat: output +
* "ViewGroup.LayoutParams={width=WIDTH, height=HEIGHT }"
*
* @hide
*/
/*返回一个封装有布局参数的字符串
* @param output
* @return
*/
public String debug(String output) {
return output +"ViewGroup.LayoutParams={width="
+ sizeToString(width) +", height=" + sizeToString(height) +" }";
}
/**
* Use {@code canvas} to draw suitabledebugging annotations for these LayoutParameters.
*
* @param view the view that contains theselayout parameters
* @param canvas the canvas on which todraw
*
* @hide
*/
/* 使用canvas为这些布局参数画一个适当的的调试注释
* @param view 包含这些布局参数的控件
* @param canvas 画调试注释的canvas
* @param paint
*/
public void onDebugDraw(View view, Canvascanvas, Paint paint) {
}
/**
* Converts the specified size to areadable String.
*
* @param size the size to convert
* @return a String instance representingthe supplied size
*
* @hide
*/
/*将大小尺寸转化为一个可读的字符串
* @param size
* @return
*/
protected static String sizeToString(int size) {
if (size == WRAP_CONTENT) {
return "wrap-content";
}
if (size == MATCH_PARENT) {
return "match-parent";
}
return String.valueOf(size);
}
}