我想使用 Flexbox 使用 React Native 创建以下网格。
我尝试使用以下代码创建此网格(有关代码和工作版本,请参见snack.expo.io),但我得到的矩形间距不正确,如下所示:
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
const Cell = () => {
return (
<View
style={styles.cell_container}
>
<View
style={styles.cell}
>
</View>
</View>
)
}
const Row = () => {
return (
<View style={styles.row_container}>
<Cell/>
<Cell/>
<Cell/>
<Cell/>
<Cell/>
<Cell/>
<Cell/>
<Cell/>
<Cell/>
<Cell/>
</View>
)
}
const Table = () => {
return (
<View style={styles.table_container}>
<Row/>
<Row/>
<Row/>
<Row/>
</View>
)
}
export default class App extends React.Component {
render() {
return (
<Table/>
);
}
}
const styles = StyleSheet.create({
table_container:{
flex: .5,
flexDirection: "column",
alignSelf: "stretch",
paddingTop: Constants.statusBarHeight,
justifyContent: 'center',
},
row_container: {
flex: 1,
flexDirection: "row",
backgroundColor: "white",
alignItems: "center",
justifyContent: "center",
},
cell_container: {
flexDirection: "row",
height: 20,
width: 20,
},
cell:{
backgroundColor: "#ebedf0",
flex: .5,
}
});