Reputation: 1060
I'm confused about crossAxisAlignment
and mainAxisAlignment
. Can anyone please explain it in simple words?
Upvotes: 85
Views: 70126
Reputation: 1
In Row Main Axis Alignment run horizontally and Cross Axis Alignment run vertically. In Column Main Axis Alignment run vertically and Cross Axis Alignment run Horizontally.
Upvotes: 0
Reputation: 2041
This two pictures are clear to show the meaning of MainAxisAlignment and CrossAxisAlignment.
Upvotes: 17
Reputation: 390
Depends on you how you wanna put your content on screen. we need to use mainAxis & CrossAxis alignment properties.
For more basic layout concepts: https://flutter.dev/docs/codelabs/layout-basics
Upvotes: 5
Reputation: 5935
In a column,
In a row,
Upvotes: 2
Reputation: 268244
For Row:
mainAxisAlignment
= Horizontal Axis
crossAxisAlignment
= Vertical Axis
For Column:
mainAxisAlignment
= Vertical Axis
crossAxisAlignment
= Horizontal Axis
Upvotes: 187
Reputation: 3705
When you use a Row
, its children are laid out in a row, which is horizontally. So a Row
's main axis is horizontal.
Using mainAxisAlignment
in a Row
lets you align the row's children horizontally (e.g. left, right).
The cross axis to a Row
's main axis is vertical. So using crossAxisAlignment
in a Row
lets you define, how its children are aligned vertically.
In a Column
, it's the opposite. The children of a column are laid out vertically, from top to bottom (per default). So its main axis is vertical. This means, using mainAxisAlignment
in a Column
aligns its children vertically (e.g. top, bottom) and crossAxisAlignment
defines how the children are aligned horizontally in that Column.
Upvotes: 4
Reputation: 277517
Row
/Column
are associated to an axis:
Row
Column
mainAxisAlignment
is how items are aligned on that axis. crossAxisAlignment
is how items are aligned on the other axis.
Upvotes: 6