-
{@hide}
-
同理
*/
protected int mRight; -
所以,这只是一个通过加减得到的一个相对值,并不是真正测量得到的尺寸;
getMeasuredWidth
- Like {@link #getMeasuredWidthAndState()}, but only returns the
- raw width component (that is the result is masked by
- {@link #MEASURED_SIZE_MASK}).
- @return The raw measured width of this view. 原始宽度
*/
public final int getMeasuredWidth() {
return mMeasuredWidth & MEASURED_SIZE_MASK;
}
- 这里有两个变量,一个是 mMeasuredWidth,一个是 MEASURED_SIZE_MASK
/**
- Bits of {@link #getMeasuredWidthAndState()} and
- {@link #getMeasuredWidthAndState()} that provide the actual(真实的) measured size.
*/
public static final int MEASURED_SIZE_MASK = 0x00ffffff;
MEASURED_SIZE_MASK 是一个16进制的树,这里需要说明一下,view 的测量结果,它封装在:MeasureSpec类中,主要包含测量结果和测量模式,有三种,分别是:MeasureSpec.UNSPECIFIED,MeasureSpec.AT_MOST,MeasureSpec.EXACTLY,MeasureSpec通过makeMeasureSpec() 方法将模式和 大小,封装在了一起,一个int值,高2位是测量模式,低30位是view的尺寸;
mMeasuredWidth 的值是怎么设置上的;
-
流程子view 的 onMeasure()---->setMeasuredDimension()----->setMeasuredDimensionRaw()
-
第一步 :setMeasuredDimension();
/**
-
This method must be called by {@link #onMeasure(int, int)} to store the
- measured width and measured height. Failing to do so will trigger an
- exception at measurement time.
- 这个方法必须在onMeasure(int, int)中调用
- @param measuredWidth The measured width of this view. May be a complex
- bit mask as defined by {@link #MEASURED_SIZE_MASK} and
- {@link #MEASURED_STATE_TOO_SMALL}.
- @param measuredHeight The measured height of this view. May be a complex
- bit mask as defined by {@link #MEASURED_SIZE_MASK} and
- {@link #MEASURED_STATE_TOO_SMALL}.
*/
protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) {
boolean optical = isLayoutModeOptical(this)
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
;
if (optical != isLayoutModeOptical(mParent)) {
Insets insets = getOpticalInsets();
int opticalWidth = insets.left + insets.right;
int opticalHeight = insets.top + insets.bottom;
measuredWidth += optical ? opticalWidth : -opticalWidth;
measuredHeight += optical ? opticalHeight : -opticalHeight;
}
// 设置view的原始尺寸
setMeasuredDimensionRaw(measuredWidth, measuredHeight);
}
第二步:setMeasuredDimensionRaw();
/**
*
- Sets the measured dimension without extra processing for things like optical bounds.
- Useful for reapplying consistent values that have already been cooked with adjustments
- for optical bounds, etc. such as those from the measurement cache.
- @param measuredWidth The measured width of this view. May be a complex
- bit mask as defined by {@link #MEASURED_SIZE_MASK} and
- {@link #MEASURED_STATE_TOO_SMALL}.
- @param measuredHeight The measured height of this view. May be a complex
- bit mask as defined by {@link #MEASURED_SIZE_MASK} and
- {@link #MEASURED_STATE_TOO_SMALL}.
*/
private void setMeasuredDimensionRaw(int measuredWidth, int measuredHeight) {
mMeasuredWidth = measuredWidth;
mMeasuredHeight = measuredHeight;
mPrivateFlags |= PFLAG_MEASURED_DIMENSION_SET;