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。
创建个最简单的界面,代码如下图![](https://img.haomeiwen.com/i1656374/9afa644e58f98fa0.png)
1、flexDirection :'row'时,改变justifyContent的情况:
![](https://img.haomeiwen.com/i1656374/1b0b79a895721c9d.png)
![](https://img.haomeiwen.com/i1656374/9b7a31544b2b704b.png)
![](https://img.haomeiwen.com/i1656374/022072b5a0196da6.png)
![](https://img.haomeiwen.com/i1656374/129fd2cb4f9c8595.png)
![](https://img.haomeiwen.com/i1656374/e7727d5209ebee00.png)
2、flexDirection :'column'时,改变justifyContent的情况:
![](https://img.haomeiwen.com/i1656374/70e4f03ea19f7fe3.png)
![](https://img.haomeiwen.com/i1656374/e231b1bab6a627fb.png)
![](https://img.haomeiwen.com/i1656374/6d6745eb821a2218.png)
![](https://img.haomeiwen.com/i1656374/5d9b408190ed08b8.png)
![](https://img.haomeiwen.com/i1656374/ac2aaed9d6b23e9b.png)
3、flexDirection :'row', justifyContent:'center'时,改变alignItems的情况:
![](https://img.haomeiwen.com/i1656374/eade3ba4f22fbe03.png)
![](https://img.haomeiwen.com/i1656374/a9f9940ed28b0bd2.png)
![](https://img.haomeiwen.com/i1656374/e951103fa44f4a1a.png)
![](https://img.haomeiwen.com/i1656374/96d42df2654d2a0d.png)
注意:要使stretch选项生效的话,子元素在次轴方向上不能有固定的尺寸。
![](https://img.haomeiwen.com/i1656374/c608a19770dc10c4.png)
网友评论