React-Native flexDirection:带有多行的'row'

Mar*_*ner 14 react-native

我想知道是否有一种方法可以flexDirection: 'row'使用多行.因为现在如果我在行中有10个对象,则会进入第二行.这是我在文档中添加另外两个<View>元素的示例

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

export default 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, height: 50, backgroundColor: 'skyblue'}} />
        <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />
        <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />
        <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />
      </View>
    );
  }
};

// skip this line if using Create React Native App
AppRegistry.registerComponent('AwesomeProject', () => FlexDirectionBasics);
Run Code Online (Sandbox Code Playgroud)

sou*_*tot 24

您可以使用,flex-wrap: wrap因此当内容达到此组件允许的最大宽度时,内容将断开到新行.

      <View style={{flex: 1, flexDirection: 'row', flexWrap: 'wrap'}}>
        <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={{width: 50, height: 50, backgroundColor: 'skyblue'}} />
        <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />
      </View>
Run Code Online (Sandbox Code Playgroud)

https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap

希望能帮助到你