话不多说,上图:
LayoutParams是什么?与MeasureSpec有关系吗?
LayoutParams:直接从表面看就知道,是布局的参数。ViewGroup里面的一个静态类
public static class LayoutParams {
/**
* Special value for the height or width requested by a View.
* FILL_PARENT means that the view wants to be as big as its parent,
* minus the parent's padding, if any. This value is deprecated
* starting in API Level 8 and replaced by {@link #MATCH_PARENT}.
*/
@SuppressWarnings({"UnusedDeclaration"})
@Deprecated
public static final int FILL_PARENT = -1;
/**
* Special value for the height or width requested by a View.
* MATCH_PARENT means that the view wants to be as big as its parent,
* minus the parent's padding, if any. Introduced in API Level 8.
*/
public static final int MATCH_PARENT = -1;
/**
* Special value for the height or width requested by a View.
* WRAP_CONTENT means that the view wants to be just large enough to fit
* its own internal content, taking its own padding into account.
*/
public static final int WRAP_CONTENT = -2;
public int width;
.
.
.
.
}
那么和MeasureSpec有什么关系呢?
子view通过getChildMeasureSpec()方法传入layoutparams获取对应的MeasureSpec,由于子view的测量。
MeasureSpec是什么呢?
MeasureSpec是View中的内部类,用于保存宽高的信息(int 累心,32位,高2位标识Mode:UNSPECIFIED、EXACTLY、AT_MOST,低30位标识size)
UNSPECIFIED:不对View大小做限制
EXACTLY:确切的大小:如 100dp
AT_MOST:大小不可超过某个数值,如:match_parent,做大不能超过parent