一、函数getMeasuredWidth() :
可以先看一下View / ViewGroup关于 getMeasuredWidth 这个函数的源码:
public final int getMeasuredWidth() {
return mMeasuredWidth & MEASURED_SIZE_MASK;
}
其中 mMeasuredWidth 是由我们在View的onMeasure阶段中使用 setMeasuredDimension 这个函数传入的。
setMeasuredDimension(int measuredWidth, int measuredHeight)
而 MEASURED_SIZE_MASK 是一个静态常量,我想它是用来限制mMeasuredWidth的大小吧。
public static final int MEASURED_SIZE_MASK = 0x00ffffff;
所以,我们的 getMeasuredWidth() 所返回的值与 该View / ViewGroup 在调用 setMeasuredDimension 后才会有一定的值,且由 setMeasuredDimension 决定返回值的大小。
二、函数getWidth():
接下来再看一下 View 关于 getWidth 这个函数的源码:
public final int getWidth() {
return mRight - mLeft;
}
而 mRight 和 mLeft 是在 View 的 setFrame / setOpticalFrame 函数中被赋值的。<