react-native之flex布局总结
2017-04-22 10:21
465 查看
flex布局之横纵布局
当 flexDirection 为 row 的时候,为横向布局 , 当 flexDirection 为 column 的时候,为纵向布局
Justify Content
在组件的style中指定justifyContent可以决定其子元素沿着主轴的排列方式。子元素是应该靠近主轴的起始端还是末尾段分布呢?亦或应该均匀分布?对应的这些可选项有:flex-start、center、flex-end、space-around以及space-between。
需要注意的是 Justify Content 同 flexDirection=’row’ 配合使用,如:
而如果此时 flexDirection: ‘column’, 那么在 justifyContent 为 center、flex-end、space-around的时候都会显示异常,由此可见 justifyContent 更适合与 flexDirection=’row’ 配合使用;
而相对的alignItems就更适合同 flexDirection: ‘column’,使用了,如:
在组件的style中指定alignItems可以决定其子元素沿着次轴(与主轴垂直的轴,比如若主轴方向为row,则次轴方向为column)的排列方式。子元素是应该靠近次轴的起始端还是末尾段分布呢?亦或应该均匀分布?对应的这些可选项有:flex-start、center、flex-end以及stretch。
注意:要使stretch选项生效的话,子元素在次轴方向上不能有固定的尺寸。以下面的代码为例:只有将子元素样式中的width: 50去掉之后,alignItems: ‘stretch’才能生效。 stretch在width去掉后会自动拓展延伸。
<View style={{flex: 1, flexDirection: 'row'}}> <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} /> <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} /> <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} /> </View>
当 flexDirection 为 row 的时候,为横向布局 , 当 flexDirection 为 column 的时候,为纵向布局
Justify Content
在组件的style中指定justifyContent可以决定其子元素沿着主轴的排列方式。子元素是应该靠近主轴的起始端还是末尾段分布呢?亦或应该均匀分布?对应的这些可选项有:flex-start、center、flex-end、space-around以及space-between。
需要注意的是 Justify Content 同 flexDirection=’row’ 配合使用,如:
<View style={{ flex: 1, flexDirection: 'row', justifyContent: 'space-between', }}> <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} /> <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} /> <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} /> </View>
而如果此时 flexDirection: ‘column’, 那么在 justifyContent 为 center、flex-end、space-around的时候都会显示异常,由此可见 justifyContent 更适合与 flexDirection=’row’ 配合使用;
而相对的alignItems就更适合同 flexDirection: ‘column’,使用了,如:
<View style={{ flex: 1, flexDirection: 'column', justifyContent: 'center', alignItems: 'center', }}> <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} /> <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} /> <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} /> </View>
在组件的style中指定alignItems可以决定其子元素沿着次轴(与主轴垂直的轴,比如若主轴方向为row,则次轴方向为column)的排列方式。子元素是应该靠近次轴的起始端还是末尾段分布呢?亦或应该均匀分布?对应的这些可选项有:flex-start、center、flex-end以及stretch。
注意:要使stretch选项生效的话,子元素在次轴方向上不能有固定的尺寸。以下面的代码为例:只有将子元素样式中的width: 50去掉之后,alignItems: ‘stretch’才能生效。 stretch在width去掉后会自动拓展延伸。
相关文章推荐
- 《React-Native系列》11、 图解RN布局之FlexBox,三分钟上手写RN界面
- [Wondgirl]从零开始学React Native之FlexBox布局(三)
- React-Native 学习之 Flex布局
- ReactNative (四)FlexBox 布局基础
- React Native之FlexBox布局上的一些心得
- React Native 弹性布局FlexBox
- React Native FlexBox布局
- 从零开始 React Native(8) flex布局_常用控件案例
- React Native实战之flexbox布局(RN基础)
- 浅谈React Native Flexbox布局(小结)
- React Native Flexbox布局
- react-native 之布局总结
- React Native FlexBox布局
- React native FlexBox布局的基本用法
- React-Native之flexbox布局篇
- ReactNative FlexBox布局
- react-native的flex布局
- React Native从零开始(二)Flexbox布局,和布局属性
- React Native FlexBox布局(二) 应用篇
- React-Native 学习之 Flex布局