rn版本: 0.38
只需使用flex指定图像样式,没有宽度和高度,但图像将不会在移动屏幕上显示。如何做到这一点。
<View style={styles.container}>
<Image style={styles.image} source={{uri : 'https://www.baidu.com/img/bd_logo1.png'}}>
</Image>
</View>
const styles = StyleSheet.create({
container: {
flex: 1
},
image: {
flex: 1,
resizeMode: 'contain'
},
});发布于 2021-12-12 05:09:40
可以在不指定大小的情况下在Image上使用flexGrow: 1或flex: 1,但需要使用百分比或固定大小设置容器width和height:
<View style={{ width: "100%", height: "100%" }}>
<Image
source={{
uri: "https://github.githubassets.com/images/modules/logos_page/GitHub-Logo.png",
}}
style={{ flex: 1 }}
resizeMode="contain"
/>
</View>https://stackoverflow.com/questions/40910421
复制相似问题