protected override void onLayout(System.Drawing.RectangleF newPosition, bool parentHidden) { // Make room for padding newPosition = newPosition.ApplyInsets(Padding); if (!parentHidden && Visible) { // Position each view according to it's gravity foreach (var v in SubViews) { if (v.Gone) { v.Layout(RectangleF.Empty, false); continue; } // If subview has a gravity specified, use it, otherwise use our own var g = v.LayoutParameters.Gravity; if (g == Gravity.None) { g = this.Gravity; } // Get it's size var size = v.GetMeasuredSize(); // Work out it's position by apply margins and gravity var subViewPosition = newPosition.ApplyInsets(v.LayoutParameters.Margins).ApplyGravity(size, g); // Position it v.Layout(subViewPosition, false); } } }