【问题标题】:Flexbox generator does not display well in my react applicationFlexbox 生成器在我的反应应用程序中显示不好
【发布时间】:2020-02-08 19:53:53
【问题描述】:

我正在测试 https://yogalayout.com/playground 并创建了该模板:

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

export default class MyLayout extends Component {
  render() {
    return (
      <View style={{
        flex: 1,
        width: 500,
        height: 500,
        justifyContent: 'space-between',
      backgroundColor: 'red',
      }}>
        <View style={{
          flex: 1,
          width: 100,
          height: 100,
          backgroundColor: 'blue',
        }} />
        <View style={{
          flex: 1,
          width: 100,
          height: 100,
          backgroundColor: 'green',
        }} />
        <View style={{
          flex: 1,
          width: 100,
          height: 100,
          backgroundColor: 'purple',
        }} />
      </View>
    );
  }
};

我希望得到这样的结果:

相反,我有这个:

什么会破坏我的 flexbox 布局?

【问题讨论】:

  • flexDirection: "row" 添加到您的父视图

标签: javascript css react-native flexbox react-native-web


【解决方案1】:

在 React Native 中默认的 flexDirectioncolumn。因此,请尝试在您的容器 View 中将其设置为 row

<View style={{
        flex: 1,
        width: 500,
        height: 500,
        justifyContent: 'space-between',
        backgroundColor: 'red',
        flexDirection: "row"
      }}>
  .
  .
  .

【讨论】:

  • 它与默认浏览器行为有什么不同吗?
  • 移动端开发更方便。 @EmielZuurbier
  • 我已经在 web 中进行了测试,而不是在本机中,所以这不是答案。或者你确定默认还是不同? (来源?)
  • "所以这不是答案" 你试过了吗? @DimitriKopriwa
  • 就是这样。谢谢!
猜你喜欢
  • 1970-01-01
  • 2022-12-30
  • 2020-04-14
  • 2019-03-24
  • 1970-01-01
  • 2022-10-14
  • 1970-01-01
  • 2021-11-07
  • 2022-01-17
相关资源
最近更新 更多