getMeasuredHeight 与 getMeasuredHeightAndState

getMeasuredHeight vs getMeasuredHeightAndState

我已经看过源代码了。我已经阅读了文档。但是我仍然不明白这两个值如何比较和对比。我也很惊讶地看到

public final int getMeasuredHeight() {
    return mMeasuredHeight & MEASURED_SIZE_MASK;
}

为什么要按位与?

mMeasuredHeight 是一个整数值,包含关于视图的两条不同的信息。

很明显,第一块是尺码。视图可以有一个合理的最大高度,它远小于最大整数。因此,您可以使用整数值中的最高位来设置标志。

在这种情况下,设置的标志是MEASURED_STATE_TOO_SMALL,这是第二块。通过将此位设置为 1,视图声明 "measured size is smaller that the space the view would like to have."

getMeasuredHeight 通过任何使用原始像素值的函数执行按位与运算以消除该位。