1ViewGroup的onMeasure方法,测量的值应该是父容器的内边距加上所有子元素的测量宽高和外边距,自定义View时最好让view支持wrap_content,如果有必要,让你的view支持padding。
2
getMeasureWidth()方法在measure()过程结束后就可以获取到了,而getWidth()方法要在layout()过程结束后才能获取到。另外,getMeasureWidth()方法中的值是通过setMeasuredDimension()方法来进行设置的,而getWidth()方法中的值则是通过视图右边的坐标减去左边的坐标计算出来的。
3View的具体尺寸是通过其自身的测量规格(measureSpec)计算出来的,而View的measureSpec是由父视图的measureSpec和view自身的LayoutParams共同决定的。
4 measure过程就是用来处理match_parent或者wrap_content,假如layout中规定所有View的layout_width和layout_height必须赋值成具体的数值,那么measure其实是没有必要的,但是加入match_parent或者wrap_content,会使得布局更加灵活。
5 mesure过程中几个关键方法:
(1)public final void measue(int widthMeasureSpec, int heightMeasureSpec);
(2)protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec);
(3)protected void measureChildren(int widthMeasureSpec, int heightMeasureSpec)
(4)protected void measureChild(View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec)
(5)protected void measureChildWithMargins(View child,int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)