推荐学习资料
-
Android进阶学习全套手册
-
Android对标阿里P7学习视频
-
BAT TMD大厂Android高频面试题
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
/**
-
The distance in pixels from the left edge of this view’s parent
-
to the left edge(边缘) of this view.
-
{@hide}
-
当前view的做左边缘到父view左便于的像素距离
/
protected int mLeft;
/* -
The distance in pixels from the left edge of this view’s parent
-
to the right edge of this view.
-
{@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);
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);
新的开始
改变人生,没有什么捷径可言,这条路需要自己亲自去走一走,只有深入思考,不断反思总结,保持学习的热情,一步一步构建自己完整的知识体系,才是最终的制胜之道,也是程序员应该承担的使命。
《系列学习视频》
《系列学习文档》
《我的大厂面试之旅》
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
et/topics/618156601)**
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!