加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React-Native 基础(六) 使用Flexbox布局

发布时间:2020-12-15 03:26:16 所属栏目:百科 来源:网络整理
导读:参考文档:http://facebook.github.io/react-native/docs/flexbox.html 1. 使用flexbox可以指定子布局 2. flexbox兼容不同尺寸的手机屏幕 3. 通常使用 flexDirection , alignItems ,和 justifyContent 的组合实现目标效果 flexDirection 指定子布局是横向(r

参考文档:http://facebook.github.io/react-native/docs/flexbox.html
1. 使用flexbox可以指定子布局
2. flexbox兼容不同尺寸的手机屏幕
3. 通常使用flexDirection,alignItems,和justifyContent的组合实现目标效果

flexDirection
指定子布局是横向(row)还是纵向(column),默认是纵向

import React,{ Component } from 'react'; import { AppRegistry,View } from 'react-native'; class FlexDirectionBasics extends Component { render() { return ( // Try setting `flexDirection` to `column`. <View style={{flex: 1,flexDirection: 'row'}}> <View style={{width: 50,height: 50,backgroundColor: 'powderblue'}} /> <View style={{width: 50,backgroundColor: 'skyblue'}} /> <View style={{width: 50,backgroundColor: 'steelblue'}} /> </View> ); } }; AppRegistry.registerComponent('AwesomeProject',() => FlexDirectionBasics);

justifyContent
决定子布局沿着主轴的分布,可选项有flex-start,center,flex-end,space-aroundspace-between.

import React,View } from 'react-native'; class JustifyContentBasics extends Component { render() { return ( // Try setting `justifyContent` to `center`. // Try setting `flexDirection` to `row`. <View style={{ flex: 1,flexDirection: 'column',justifyContent: 'space-between',}}> <View style={{width: 50,() => JustifyContentBasics);

alignItems
alignItems决定子布局沿着副轴(如果主轴是纵轴,那么副轴是横轴,反之亦然)的对齐方式。可选项:flex-start,和stretch. 使用stretch时要注意:只有当子布局在副轴上没有固定尺寸时,stretch才有效(这玩意儿相当于match-parent)。

更多的布局参见 http://facebook.github.io/react-native/docs/layout-props.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读