在Android源代码中,有一个块表示什么时候不应该调用onMeasure
,这意味着在满足以下条件后,如果满足以下条件,就不会调用onMeasure
。
// Optimize layout by avoiding an extra EXACTLY pass when the view is
// already measured as the correct size. In API 23 and below, this
// extra pass is required to make LinearLayout re-distribute weight.
//my understanding: parent measure mode or height/width is changed
final boolean specChanged = widthMeasureSpec != mOldWidthMeasureSpec
|| heightMeasureSpec != mOldHeightMeasureSpec;
//my understanding: parent measure mode is Exactly
final boolean isSpecExactly = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY
&& MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY;
//my understanding: last current(child) view measurement is the same as parent measurement
final boolean matchesSpecSize = getMeasuredWidth() == MeasureSpec.getSize(widthMeasureSpec)
&& getMeasuredHeight() == MeasureSpec.getSize(heightMeasureSpec);
final boolean needsLayout = specChanged
&& (sAlwaysRemeasureExactly || !isSpecExactly || !matchesSpecSize);
据我了解,widthMeasureSpec
是父级度量规范。根据源代码,如果父测量方式为Exact
,并且其宽度和高度已更改,则子级不需要重新测量。
这对我来说没有意义,即使孩子是match_parent
,即使父母是正确的,当其宽度或高度发生变化时,孩子也需要进行匹配和更改。我想念什么吗?