#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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。