1,获取长宽尺寸(onMeasure(int widthMeasureSpec, int heightMeasureSpec))
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
2,测量子view
//调用ViewGroup的方法,测量子view
measureChildren(widthMeasureSpec, heightMeasureSpec);
3,计算宽度
//最大的宽
int maxWidth = 0;
//累计的高
int totalHeight = 0;
//当前这一行的累计行宽
int lineWidth = 0;
//当前这行的最大行高
int maxLineHeight = 0;
//用于记录换行前的行宽和行高
int oldHeight;
int oldWidth;