protected override void OnMeasure(LayoutMeasureSpec widthMeasureSpec, LayoutMeasureSpec heightMeasureSpec) { Console.WriteLine($"CustomLayoutHorizental OnMeasure() START"); var accumulatedWidth = new LayoutLength(0); var maxHeight = new LayoutLength(0); // this is needed, otherwise the child's LayoutItem is garbage collected! for (uint i = 0; i < ChildCount; ++i) { childLayouts[i] = GetChildAt(i); } // In this layout we will: // Measuring the layout with the children in a horizontal configuration, one after another // Set the required width to be the accumulated width of our children // Set the required height to be the maximum height of any of our children for (uint i = 0; i < ChildCount; ++i) { var childLayout = childLayouts[i]; Console.WriteLine($"child count={ChildCount}, i={i}"); if (childLayout) { MeasureChild(childLayout, widthMeasureSpec, heightMeasureSpec); accumulatedWidth += childLayout.MeasuredWidth; maxHeight.Value = System.Math.Max(childLayout.MeasuredHeight.Value, maxHeight.Value); Console.WriteLine($"child layout is not NULL! accumulatedWidth={accumulatedWidth.Value}, i={i}"); } } // Finally, call this method to set the dimensions we would like SetMeasuredDimensions(new MeasuredSize(accumulatedWidth), new MeasuredSize(maxHeight)); Console.WriteLine($"CustomLayoutHorizental OnMeasure() accumlated width={accumulatedWidth.Value}, maxHeight={maxHeight.Value} END"); }
protected override void OnMeasure(LayoutMeasureSpec widthMeasureSpec, LayoutMeasureSpec heightMeasureSpec) { var accumulatedWidth = new LayoutLength(0); var maxHeight = 0; var measuredWidth = new LayoutLength(0); LayoutLength measuredHeight = new LayoutLength(0); LayoutMeasureSpec.ModeType widthMode = widthMeasureSpec.Mode; LayoutMeasureSpec.ModeType heightMode = heightMeasureSpec.Mode; bool isWidthExact = (widthMode == LayoutMeasureSpec.ModeType.EXACTLY); bool isHeightExact = (heightMode == LayoutMeasureSpec.ModeType.EXACTLY); // In this layout we will: // Measuring the layout with the children in a horizontal configuration, one after another // Set the required width to be the accumulated width of our children // Set the required height to be the maximum height of any of our children for (uint i = 0; i < ChildCount; ++i) { var childLayout = GetChildAt(i); if (childLayout) { MeasureChild(childLayout, widthMeasureSpec, heightMeasureSpec); accumulatedWidth += childLayout.MeasuredWidth; maxHeight = System.Math.Max(childLayout.MeasuredHeight.Value, maxHeight); } } measuredHeight.Value = maxHeight; measuredWidth = accumulatedWidth; if (isWidthExact) { measuredWidth = new LayoutLength(widthMeasureSpec.Size); } if (isHeightExact) { measuredHeight = new LayoutLength(heightMeasureSpec.Size); } // Finally, call this method to set the dimensions we would like SetMeasuredDimensions(new MeasuredSize(measuredWidth), new MeasuredSize(measuredHeight)); }
protected override void OnMeasure(LayoutMeasureSpec widthMeasureSpec, LayoutMeasureSpec heightMeasureSpec) { var accumulatedHeight = new LayoutLength(0); var maxWidth = new LayoutLength(0); for (uint i = 0; i < ChildCount; ++i) { childLayouts[i] = GetChildAt(i); } for (uint i = 0; i < ChildCount; ++i) { var childLayout = childLayouts[i]; if (childLayout) { MeasureChild(childLayout, widthMeasureSpec, heightMeasureSpec); accumulatedHeight += childLayout.MeasuredHeight; maxWidth.Value = System.Math.Max(childLayout.MeasuredWidth.Value, maxWidth.Value); Console.WriteLine($"CustomLayoutVertical child layout is not NULL! accumulatedHeight={accumulatedHeight.Value}, i={i}"); } } SetMeasuredDimensions(new MeasuredSize(maxWidth), new MeasuredSize(accumulatedHeight)); Console.WriteLine($"CustomLayoutVertical OnMeasure() max width={maxWidth.Value}, accumulated Height={accumulatedHeight.Value}"); }