我正在使用 flex-box 设计反应原生应用程序的 UI。但是它的代码没有显示预期的结果?
问题
Margin 属性InnerContainer2
没有margin:'5%'
垂直覆盖相等的空间。
代码:
import React, {Component} from 'react';
import {StyleSheet, Text, View} from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<View style={styles.innerContainer1}>
<View style={styles.innerContainer2}>
<Text style={styles.welcome}>This is live reload</Text>
</View>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'grey'
},
innerContainer1: {
flex: 1,
width: '80%',
margin: '10%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'lightgrey'
},
innerContainer2: {
flex: 1,
width: '80%',
margin: '5%',
height: 'auto',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'grey'
},
welcome: {
textAlign: 'center',
margin: 10,
}
});
预期产出
实际输出