react-native之flex布局总结
来源:互联网 发布:dota2比赛数据未找到 编辑:程序博客网 时间:2024/05/21 00:50
- flex布局之横纵布局
<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去掉后会自动拓展延伸。
0 0
- react-native之flex布局总结
- React Native布局之flex
- react-native 之布局总结
- react-native 之布局总结
- React-Native 学习之 Flex布局
- React-Native 学习之 Flex布局
- React Native Flex布局
- react-native flex布局
- react-native的flex布局
- React Native 之 Flex
- React Native UI布局总结
- React Native布局篇总结
- React Native——flex布局
- React Native入门教程 3 -- Flex布局
- React-Native基础_3.Flex布局
- 【React Native】flex布局基础(四)
- react-native 之布局篇
- React Native 之 flexbox布局
- 安卓实战-计算器
- 制作电子相册
- 单行函数
- POJ 2975 Nim 题解
- Android 同一个BroadcastReceiver在两个程序里执行
- react-native之flex布局总结
- oracle中三大类型与隐式数据类型转换
- caffe2 在树莓派raspberry Pi 3b平台应用(一 源码编译注意事项)
- 并查集总结
- caffe2 介绍
- Ubuntu系统重启后/etc/resolv.conf内容丢失
- win10 禁用更新
- SQL&&SQLPLUS语句的特点,单双引号出现的位置
- POJ_1159_Palindrome【dp】