美文网首页
FlexBox布局(RN官网所得)

FlexBox布局(RN官网所得)

作者: 月魂king | 来源:发表于2018-03-15 16:00 被阅读0次

Flex Direction

决定布局的主轴,默认(row)竖直轴。

import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';

class FlexDirectionBasics extends Component {
  render() {
    return (
      // 尝试把`flexDirection`改为`column`看看
      <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>
    );
  }
};

AppRegistry.registerComponent('AwesomeProject', () => FlexDirectionBasics);

justify Content

在组件的style中指定justifyContent可以决定其子元素沿着主轴的排列方式。子元素是应该靠近主轴的起始端还是末尾段分布呢?亦或应该均匀分布?对应的这些可选项有:flex-start、center、flex-end、space-around以及space-between。

import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';

class JustifyContentBasics extends Component {
  render() {
    return (
      // 尝试把`justifyContent`改为`center`看看
      // 尝试把`flexDirection`改为`row`看看
      <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>
    );
  }
};

AppRegistry.registerComponent('AwesomeProject', () => JustifyContentBasics);

Align Items

在组件的style中指定alignItems可以决定其子元素沿着次轴(与主轴垂直的轴,比如若主轴方向为row,则次轴方向为column)的排列方式。子元素是应该靠近次轴的起始端还是末尾段分布呢?亦或应该均匀分布?对应的这些可选项有:flex-start、center、flex-end以及stretch。

注意:要使stretch选项生效的话,子元素在次轴方向上不能有固定的尺寸。以下面的代码为例:只有将子元素样式中的width: 50去掉之后,alignItems: 'stretch'才能生效。

import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';

class AlignItemsBasics extends Component {
  render() {
    return (
      // 尝试把`alignItems`改为`flex-start`看看
      // 尝试把`justifyContent`改为`flex-end`看看
      // 尝试把`flexDirection`改为`row`看看
      <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>
    );
  }
};

AppRegistry.registerComponent('AwesomeProject', () => AlignItemsBasics);

相关文章

  • FlexBox布局(RN官网所得)

    Flex Direction 决定布局的主轴,默认(row)竖直轴。 justify Content 在组件的st...

  • React-Native中的Flexbox布局

    RN 的 Flexbox 布局的学习笔记 1.什么是 Flexbox 布局? Flexbox,弹性布局,可以以响应...

  • 007_ReactNative: Layout with Fle

    (问渠那得清如许,为有源头活水来。 双手奉上RN官网) Flexbox: 用于在不同的屏幕上显示相同的布局. 需要...

  • React Native布局

    RN布局 RN的flexbox主要有以下几个属性alignItems,alignSelf,flex,flexDir...

  • RN布局-Flexbox

    Yoga Facebook在React Native里引入了一种跨平台的基于CSS的布局系统,它实现了Flexbo...

  • React Native 布局

    RN布局 盒子模型 RN的flexbox主要有以下几个属性alignItems,alignSelf,flex,fl...

  • Flexbox总结

    Flexbox弹性布局是React Native中的布局,功能丰富,能够满足页面大量的排版需求。RN的FlexBo...

  • React-Native 认识style_3

    3.1 RN页面布局flexbox 当听到flexbox, 作为一个纯碎的iOS开发者,听到这个内心是懵逼的.只能...

  • ReactNative笔记-flexbox和position

    ReactNative笔记-flexbox和position 在rn中布局基本上全部是使用的flex,所以flex...

  • RN之FlexBox布局用法

    FlexBox 布局基本用法 1、什么是FlexBox Flexbox是Flexible Box的缩写,意为'弹性...

网友评论

      本文标题:FlexBox布局(RN官网所得)

      本文链接:https://www.haomeiwen.com/subject/lhehqftx.html