Flutter crossAxisAlignment vs mainAxisAlignment

后端 未结 5 2017
情深已故
情深已故 2021-01-31 14:51

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

相关标签:
5条回答
  • 2021-01-31 15:26

    For Row:

    mainAxisAlignment = Horizontal Axis
    crossAxisAlignment = Vertical Axis


    For Column:

    mainAxisAlignment = Vertical Axis
    crossAxisAlignment = Horizontal Axis

    Image source

    0 讨论(0)
  • 2021-01-31 15:36

    This two pictures are clear to show the meaning of MainAxisAlignment and CrossAxisAlignment.

    (Pictures are from Network)

    0 讨论(0)
  • 2021-01-31 15:41

    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.

    0 讨论(0)
  • 2021-01-31 15:44

    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.
    0 讨论(0)
  • 2021-01-31 15:47

    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.

    0 讨论(0)
提交回复
热议问题