首页 > 解决方案 > 为什么容器样式不适用于 React Native 中的 View 组件

问题描述

我正在开发一个 React 项目,在该项目中,为什么容器样式不适用于 react native 中的 View Component。

这是 App.js

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

const App = () => {
  return (
    <View style={([styles.container], {flex: 1}, {flexDirection: 'column'})}>
      <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>
  );
};

const styles = StyleSheet.create({
  container: {
    padding: 10,
    marginTop: 10,
  },
});

export default App;

标签: react-native

解决方案


我认为您应该将视图容器样式编辑为此

style={[styles.container, {flex: 1, flexDirection: 'column'}]}

希望有帮助。


推荐阅读