1 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2 (。。。。。。)
3
4 int maxHeight = 0;//记录最大的宽高
5
6 int maxWidth = 0;
7 int childState = 0;
8
9 for (int i = 0; i < count; i++) {
10 final View child = getChildAt(i);
11 if (mMeasureAllChildren || child.getVisibility() != GONE) {
12 measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);//测绘所有子view
13 final LayoutParams lp = (LayoutParams) child.getLayoutParams();
14 maxWidth = Math.max(maxWidth,
15 child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
16 maxHeight = Math.max(maxHeight,
17 child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
18 childState = combineMeasuredStates(childState, child.getMeasuredState());
19 if (measureMatchParentChildren) {
20 if (lp.width == LayoutParams.MATCH_PARENT ||
21 lp.height == LayoutParams.MATCH_PARENT) {
22 mMatchParentChildren.add(child);//保存需要重新测绘的子view
23 }
24 }
25 }
26 }
27
28 (。。。。。。)
29 if (count > 1) {
30 for (int i = 0; i < count; i++) {
31 <pre name="code" class="java" style="font-size: 13.3333px;"> (。。。。。。)
32 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);//重新测绘子view } } }