首先,了解下官方概念。
flexDirection
在组件的style中指定flexDirection可以决定布局的主轴。子元素是应该沿着水平轴(row)方向排列,还是沿着竖直轴(column)方向排列呢?默认值是竖直轴(column)方向。
justifyContent
在组件的style中指定justifyContent可以决定其子元素沿着主轴的排列方式。子元素对应的这些可选项有:flex-start、center、flex-end、space-around以及space-between。
alignItems
在组件的style中指定alignItems可以决定其子元素沿着次轴(与主轴垂直的轴,比如若主轴方向为row,则次轴方向为column)的排列方式。子元素对应的这些可选项有:flex-start、center、flex-end以及stretch。
创建个最简单的界面,代码如下图

-
flexDirection :'row'
时,改变justifyContent
的情况:





-
flexDirection :'column'
时,改变justifyContent
的情况:





-
flexDirection :'row', justifyContent:'center'
时,改变alignItems
的情况:




-
注意:要使stretch选项生效的话,子元素在次轴方向上不能有固定的尺寸。
网友评论