【发布时间】:2018-08-19 06:22:40
【问题描述】:
所以我在学习 React Native Flex,遇到了这个问题:
- 标题:红色
- 主体:绿色
- 页脚:蓝色
让我们只关注正文及其内容。
<View style={styles.body}>
<View style={styles.container}>
<View style={styles.yellow}></View>
<View style={styles.orange}></View>
</View>
</View>
body: {
flex: 15,
justifyContent: 'center',
alignContent: 'center',
}
在 Body 内部,我想要一个类似容器的容器,里面可以容纳元素。
1) 如果我给 flex
container: {
flex: 0.9,
flexDirection: 'row',
}
2) 如果我给出宽度和高度,只有宽度有效。
container: {
flex: 1,
flexDirection: 'row',
width: '90%',
height: '90%', // doesn't work?
alignSelf: 'center' // had to add this, without it, container would stick to left side
}
3) 将边距添加为百分比,将整个容器粘在底部,并且 alignSelf 不起作用。
4) 将边距添加为数字,可行,但我想避免纯数字,因为它们在其他设备上看起来不同。 (另外,这是需要的)
如何实现上一张图片的效果,但只能使用 flex 和 width,height in %?有没有可能?
另外,这样的案例有什么好的做法?
【问题讨论】:
标签: react-native layout flexbox