83

I'm confused about crossAxisAlignment and mainAxisAlignment. Can anyone please explain it in simple words?

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
callmejeevan
  • 1,040
  • 1
  • 9
  • 18

7 Answers7

184

For Row:

mainAxisAlignment = Horizontal Axis
crossAxisAlignment = Vertical Axis

enter image description here


For Column:

mainAxisAlignment = Vertical Axis
crossAxisAlignment = Horizontal Axis

enter image description here

Image source

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
16

This two pictures are clear to show the meaning of MainAxisAlignment and CrossAxisAlignment. enter image description here enter image description here

(Pictures are from Network)

prosach
  • 312
  • 2
  • 14
Ellie Zou
  • 2,021
  • 2
  • 16
  • 21
6

Row/Column are associated to an axis:

  • Horizontal for Row
  • Vertical for Column

mainAxisAlignment is how items are aligned on that axis. crossAxisAlignment is how items are aligned on the other axis.

Rémi Rousselet
  • 256,336
  • 79
  • 519
  • 432
5

Oncept

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

Tuhin
  • 194
  • 4
  • 16
4

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.

Sebastian Engel
  • 3,500
  • 32
  • 30
2

In a column,

  • to center(or align) vertically, mainAxisAlignment is used.
  • to center(or align) horizontally, crossAxisAlignment is used.

In a row,

  • to center(or align) horizontally, mainAxisAlignment is used.
  • to center(or align) vertically, crossAxisAlignment is used.
oiyio
  • 5,219
  • 4
  • 42
  • 54
0

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.