#Flutter的MainAxisAlignment用法
Row是橫向排列Widget,類屬于androi的Linerlayout橫向布局,
Column是縱向排列Widget,類屬于androi的Linerlayout橫向布局
Row({
key
mainAxisAlignment
mainAxisSize
crossAxisAlignment
textDirection
verticalDirection
textBaseline
children
})
```
就針對MainAxisAlignment和CrossAxisAlignment我們來一個案例分析
先創建一個Flutter工程,隨便放兩個Text,代碼如下
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
new Text(
'紅茶拿鐵', textAlign: TextAlign.center,
style: new TextStyle(
color: Colors.blue)),
new Text(
'卡布奇諾', textAlign: TextAlign.center,
style: new TextStyle(
color: Colors.red)),
],
),
對應的效果為
效果不明顯,不知道誰是誰,哪是哪,我們為每個widget加個背景,改造一下
Row(
children: <Widget>[
Container(
height: double.infinity,
color: Colors.black,
child:
new Text(
'紅茶拿鐵', textAlign: TextAlign.center,
style: new TextStyle(
color: Colors.white))),
Container(
height: double.infinity,
color: Colors.red,
child:
new Text(
'卡布奇諾', textAlign: TextAlign.center,
style: new TextStyle(
color: Colors.white))),
],
),
對應效果為
我們在row中加上mainAxisAlignment: MainAxisAlignment.spaceBetween(使中間的各個子控件間距相等)
效果如下,不理解,感覺看不出什么,我們再加兩個控件看看效果,效果如
,現在清晰了吧。其他幾個類似,當然還有一個屬性textDirection,他可以控制start的排列始末。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。