Layouts in Xamarin Forms

Rod Howarth - Envoy 


Xamarin Forms is young & has a learning curve

It's tempting to comprimise

We can avoid this by learning more about the layout system



Layout Options

Width/Height Request




Stack Layout

  • Stacks things
  • Horizontally or Vertically
  • Spacing between elements


  • Wraps other layouts
  • Makes them scrollable
  • Pairs nicely with StackLayout
  • ScrollOrientation - Vertical or Horizontal
  • Needs to know the size of its children

Layout Options

  • HorizontalOptions & VerticalOptions
  • How a view is positioned relative to its parent
  • Alignment: Start, Center, End, Fill
  • Expansion: Expand Option
  • Certain layouts may constrain the options their children can have 

Start, Center, End

  • Shrinks view to the space it needs to be
  • Start = Left/Top 
  • End = Right/Bottom 
  • Don't set a ScrollView to this
    • What is the height it 'needs to be'?
    • Will shrink to nothing


  • Attempts to fill parent container
  • Default for View base class
  • ScrollView/StackLayout keep default


  • Allows extra space in parent view to be allocated to children that have expands option
  • Only if the parent view is larger than its children
  • But not necessarily 'filled' by those children

Width/Height Request

  • Width & Height are readonly properties
  • WidthRequest and HeightRequest are requests to set
  • If Fill is set in LayoutOptions these will be ignored
  • Useful for LayoutOptions Start, Center, End 


  • Some similarities to HTML tables
  • Columns, Rows with widths/heights
  • Auto, Absolute, Star
  • RowSpan, ColumnSpan


  • Manually set x,y,width,height
  • AutoSize flag calculates width/height for you
  • Can be nested underneath other layouts


  • Makes AbsoluteLayout not so Absolute...
  • Handles calculations you might have done manually
  • Set as flags
    • PositionProportional & xProportional, yProportional
    • SizeProportional & WidthProportional, HeightProportional
    • All


  • Set flag on child
  • Set size to number between 0 and 1
    • ie width 0.25, height 0.10
  • Size will be % of layouts size
    • ie 25% width, 10% height


  • Set on child
  • Position of 0,0 is top left corner
  • 1,1 is bottom right
  • 0.5, 0.5 is middle


  • Constraints based layouts
  • Relative to Parent, Relative to View
  • Easier in code

Other Options