ReactNative基础---Layout and Flexbox
来源:互联网 发布:写sql算研发么 编辑:程序博客网 时间:2024/06/05 09:07
ReactNative基础—Layout and Flexbox
一、简介
上一篇中介绍了组件尺寸的定义方式,今天聊聊组件位置的定义方式。首先是在父组件中确定子组件的布局方式,然后选择子组件在主轴上的排列方式和次轴的排列方式。
二、基础知识
- flexDirection:决定主轴的布局方式;两种布局方式:横向(row)和纵向(column)
- justifyContent:决定子元素在主轴上的分布样式;五种样式:flex-start, center, flex-end, space-around, space-between
- alignItems:决定子元素在次轴上的分布方式;四种样式:flex-start, center, flex-end, stretch
三、应用
import React, { Component } from 'react';import { View } from 'react-native';export default class JustifyContentBasics extends Component { render() { return ( // 主轴方向是纵向 // 在纵向方向子元素均分主轴屏幕的可见长度 <View style={{ flex: 1, flexDirection: 'column', 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> ); }};
- justifyContent: flex-start 主轴的起点
- justifyContent: center 主轴的中心
- justifyContent: flex-end 主轴的末尾
- justifyContent: space-around 延主轴方向子元素左右等距分布
- justifyContent: space-between 延主轴方向均分主轴
import React, { Component } from 'react';import { View } from 'react-native';export default class AlignItemsBasics extends Component { render() { return ( // 主轴方向是纵向 // 主轴方向居中 // 次轴方向居中 // 最终效果:所有的子元素聚集在屏幕中央 <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> ); }};
- alignItems: flex-start 次轴的起点
- alignItems: center 次轴的中心
- alignItems: flex-end 次轴的末尾
- alignItems: stretch 延伸,即充满可充满的空间,有些类似flex,不过stretch更加灵活;该属性在使用的时候不可在次轴方向设置该子元素的宽度
阅读全文
0 0
- ReactNative基础---Layout and Flexbox
- ReactNative之Flexbox布局
- ReactNative FlexBox布局
- ReactNative基础---Components and Props
- ReactNative基础---State and Lifecycle
- ReactNative基础---Style and Flex
- ReactNative初学笔记1.1flexbox布局
- ReactNative初学笔记1.2flexbox布局2
- ReactNative系列之二FlexBox布局
- [ReactNative] 02--style & width/height & FlexBox
- ReactNative开发——flexbox布局
- ReactNative 基础
- React Native 之 Layout with Flexbox
- css3 flexbox layout(弹性布局)完全解析
- 基础篇章:React Native之Flexbox的讲解(Height and Width)
- ReactNative学习十四-再次弹性盒(Flexbox)
- 【RN】ReactNative基础配置
- ReactNative ListView基础功能
- 数组、链表、堆栈和队列
- 多重集组合数(动态规划(DP))
- 最大公约数欧几里得算法
- ACdream 1116 Gao the string! (扩展KMP+矩阵快速幂)
- hdu 2069 二维母函数
- ReactNative基础---Layout and Flexbox
- unity 制作动态适应的scrollview的注意点
- [转]Webview支持缩放并隐藏讨厌的缩放控制条
- 【Android源码分享】小k英语口袋
- adb devices报错总结
- malloc()和calloc()简介
- CSS3--多列布局、边框颜色、圆角、渐变效果、阴影反射
- redis ID生成器
- linux下部署jdk1.7