关于FlexBox布局,我的理解上,先确定以谁为主,谁未次,然后根据主次方向开始布局。
ReactNative中文网文档:http://reactnative.cn/docs/0.46/layout-with-flexbox.html#content
根据官方文档总结:
React Native中使用flexbox规则来指定某个组件的子元素的布局,flexbox布局样式有三种,flexDirection、justifyContent和alignItems。
1.flexDirection(确定主轴):在组件的style中指定flexDirection可以决定布局的主轴。子元素是应该沿着水平轴(row)方向排列,还是沿着竖直轴(column)方向排列呢?默认值是竖直轴(column)方向。
2.justifyContent(主轴排列方式):在组件的style中指定justifyContent可以决定其子元素沿着主轴的排列方式。
⭐️ 对应的属性值有:flex-start、center、flex-end、space-around以及space-between
△ flex-start:

△ center:

△ flex-end:

△ space-around:

△ space-between:

3.Align Items(次轴排列方式):在组件的style中指定alignItems可以决定其子元素沿着次轴(与主轴垂直的轴,比如若主轴方向为row,则次轴方向为column)的排列方式。
⭐️ 对应的属性值有:flex-start、center、flex-end以及stretch。
==》因为ReactNative默认主轴是column方向。所以以下示例主轴是默认方向。


网友评论