protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { int sizeWidth = MeasureSpec.GetSize(widthMeasureSpec) - this.PaddingRight - this.PaddingLeft; int sizeHeight = MeasureSpec.GetSize(heightMeasureSpec) - this.PaddingTop - this.PaddingBottom; MeasureSpecMode modeWidth = MeasureSpec.GetMode(widthMeasureSpec); MeasureSpecMode modeHeight = MeasureSpec.GetMode(heightMeasureSpec); int controlMaxLength = this.config.Orientation == HORIZONTAL ? sizeWidth : sizeHeight; int controlMaxThickness = this.config.Orientation == HORIZONTAL ? sizeHeight : sizeWidth; MeasureSpecMode modeLength = this.config.Orientation == HORIZONTAL ? modeWidth : modeHeight; MeasureSpecMode modeThickness = this.config.Orientation == HORIZONTAL ? modeHeight : modeWidth; lines.Clear(); LineDefinition currentLine = new LineDefinition(controlMaxLength, config); lines.Add(currentLine); int count = this.ChildCount; for (int i = 0; i < count; i++) { View child = this.GetChildAt(i); if (child.Visibility == ViewStates.Gone) { continue; } CustomLayoutParams lp = (CustomLayoutParams)child.LayoutParameters; child.Measure(GetChildMeasureSpec(widthMeasureSpec, this.PaddingLeft + this.PaddingRight, lp.Width), GetChildMeasureSpec(heightMeasureSpec, this.PaddingTop + this.PaddingBottom, lp.Height)); lp.ClearCalculatedFields(this.config.Orientation); if (this.config.Orientation == FlowLayout.HORIZONTAL) { lp.Length = child.MeasuredWidth; lp.Thickness = child.MeasuredHeight; } else { lp.Length = child.MeasuredHeight; lp.Thickness = child.MeasuredWidth; } bool newLine = lp.newLine || (modeLength != MeasureSpecMode.Unspecified && !currentLine.CanFit(child)); if (newLine) { currentLine = new LineDefinition(controlMaxLength, config); if (this.config.Orientation == VERTICAL && this.config.Direction == LAYOUT_DIRECTION_RTL) { lines.Insert(0, currentLine); } else { lines.Add(currentLine); } } if (this.config.Orientation == HORIZONTAL && this.config.Direction == LAYOUT_DIRECTION_RTL) { currentLine.AddView(0, child); } else { currentLine.AddView(child); } } this.CalculateLinesAndChildPosition(lines); int contentLength = 0; foreach (LineDefinition l in lines) { contentLength = Math.Max(contentLength, l.LineLength); } int contentThickness = currentLine.LineStartThickness + currentLine.LineThickness; int realControlLength = this.FindSize(modeLength, controlMaxLength, contentLength); int realControlThickness = this.FindSize(modeHeight, controlMaxThickness, contentThickness); this.ApplyGravityToLines(lines, realControlLength, realControlThickness); foreach (LineDefinition line in lines) { this.ApplyGravityToLine(line); this.ApplyPositionsToViews(line); } /* need to take padding into account */ int totalControlWidth = this.PaddingLeft + this.PaddingRight; int totalControlHeight = this.PaddingBottom + this.PaddingTop; if (this.config.Orientation == HORIZONTAL) { totalControlWidth += contentLength; totalControlHeight += contentThickness; } else { totalControlWidth += contentThickness; totalControlHeight += contentLength; } this.SetMeasuredDimension(ResolveSize(totalControlWidth, widthMeasureSpec), ResolveSize(totalControlHeight, heightMeasureSpec)); }