【发布时间】:2019-12-05 18:25:20
【问题描述】:
我把它当作一种锻炼。有 28 个组件。我想要最多 4 行组件,其中每行最多有 7 个组件,最少 1 个,具体取决于屏幕尺寸(然后是 28 行)。你能帮我完成这个吗?我知道我可以使用 flex-wrap: wrap 样式,但我希望连续最多有 7 个组件。请帮我解决这个问题,因为我是 React Native 和 Flexbox 的新手。
<View style={styles.container}>
<View style={{ flex: 1, margin: 2, height: 40, backgroundColor: 'red'}}></View>
<View style={{ flex: 1, margin: 2, height: 40, backgroundColor: 'green'}}></View>
<View style={{ flex: 1, margin: 2, height: 40, backgroundColor: 'yellow'}}></View>
<View style={{ flex: 1, margin: 2, height: 40, backgroundColor: 'brown'}}></View>
<View style={{ flex: 1, margin: 2, height: 40, backgroundColor: 'blue'}}></View>
<View style={{ flex: 1, margin: 2, height: 40, backgroundColor: 'red'}}></View>
<View style={{ flex: 1, margin: 2, height: 40, backgroundColor: 'green'}}></View>
.
.
.
</View>
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
},
});
【问题讨论】:
-
minWidth: `${100/7}%`怎么样?
标签: reactjs react-native flexbox