【发布时间】:2021-11-08 07:50:13
【问题描述】:
我正在尝试在 react native 中将图像添加到视图中,并且我希望图像覆盖视图的整个宽度,因此我在样式中添加了 width: '100%',但我需要以整数形式输入高度要显示的图像。这就是我的代码的样子:
const SplashScreen = () => {
return (
<View style={styles.container}>
<Text>Splash Screen</Text>
<Image
source={require('../assets/Login.png')}
style={styles.logo}
/>
</View>
)
}
export default SplashScreen
const styles = StyleSheet.create({
logo: {
flex: 1,
width: '100%',
height: 300,
resizeMode: 'contain',
}
}
我想使用 height:auto 之类的东西,而不是硬编码 height:300
这就是 vie 的样子:
谢谢大家
编辑:对于其他想知道的人,我只是在styles.container 中添加了一个height:'100%',然后我只需使用flex 调整图像的高度
示例:
logo: {
flex: 0.5,
width: '100%',
resizeMode: 'contain',
backgroundColor: 'red'
}
【问题讨论】:
标签: android react-native expo