React Native 第二天
来源:互联网 发布:网络销售投资 编辑:程序博客网 时间:2024/06/05 20:24
4、FlexBox/弹性布局
Flex用于对界面进行适配的一个属性,相当于Android中的LinearLayout的weight属性,可以把屏幕分成几份供控件去显示:
import React, {Component} from 'react';import { AppRegistry, StyleSheet, Text, View} from 'react-native';export default class Main extends Component { render() { return ( <View style={styles.container}> <View style={{flex: 5, backgroundColor: 'green'}} ></View> <View style={{flex: 1, backgroundColor: 'blue'}} ></View> </View> ); }}const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'red' }});
上面的这段代码就是把屏幕在竖直方向上分成6份,上面占5份,下面占1份.
5、FlexDirection
FlexDirection是用来改变主轴和侧轴对齐方向的一个属性,默认主轴是竖直方向,侧轴是水平方向.属性的值有row(水平方向),row-reverse(水平方向翻转),column(竖直方向),column-reverse(竖直方向翻转)
import React, {Component} from 'react';import { AppRegistry, StyleSheet, Text, View} from 'react-native';export default class Main extends Component { render() { return ( <View style={styles.container}> <View style={styles.viewStyle}><Text style={styles.textStyle}>{'1'}</Text></View> <View style={styles.viewStyle}><Text style={styles.textStyle}>{'2'}</Text></View> <View style={styles.viewStyle}><Text style={styles.textStyle}>{'3'}</Text></View> <View style={styles.viewStyle}><Text style={styles.textStyle}>{'4'}</Text></View> </View> ); }}const styles = StyleSheet.create({ container: { flex: 1, }, viewStyle: { width: 100, height: 100, backgroundColor: 'red', margin: 10 }, textStyle: { color: '#fff', fontSize: 20 }});
上面这段代码就是屏幕上会显示竖直排列的4个色块,默认的对齐方式是按照主轴竖直方向排列.但在实际开发中有时候需要让它水平排列,只需要将flexDirection的方向变成横向的
const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'row' //主轴方向变成横向 }, viewStyle: { width: 100, height: 100, backgroundColor: 'red', margin: 10 }, textStyle: { color: '#fff', fontSize: 20 }});
6、FlexWrap
flexwrap是用来设置超出父容器是否换行(wrap nowrap)
const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'row', //主轴方向变成横向 flexWrap:'wrap' //设置换行 }, viewStyle: { width: 100, height: 100, backgroundColor: 'red', margin: 10 }, textStyle: { color: '#fff', fontSize: 20 }});
阅读全文
0 0
- React Native 第二天
- React Native学习第二天
- 第二章、React-Native生命周期
- React Native(第二节点击事件)
- VS Code --第二大React Native 编辑器
- React native学习第二章:State
- React Native 第四天
- React Native 第六天
- React Native 第十天
- React Native 第十二天
- 【React Native 安卓开发】----(Flexbox布局)【第二篇】
- react Native push传值 第二个页面接收不到数据
- react native
- React Native
- React Native
- React- Native
- react-native
- React Native
- Leetcode OJ 70 Climbing Stairs [Easy]
- c++强制类型转换补充
- 输入一个正整数数组,输入一个正整数数组,把数,打印能拼接出的所有数字中最小的一个。例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323。
- Python安装配置教程
- 羊皮卷之八
- React Native 第二天
- (93)DataStream(操作基本数据类型)、ByteArrayStream(操作字节数组)
- python selenium 1
- MySQL 插入数据
- VC中串口使用的详细解答--包括串口编程的流程
- Rails 入门 —— 新建一个blog程序
- java 使用面向对象方式实现录入学生信息,取出成绩最大值、最小值、平均值、对其进行排序
- 剑指Offer:二叉树的深度(一刷)
- iconfont 实践及使用优化