gpt4 book ai didi

reactjs - react-native:未设置宽度或高度时不显示图像

转载 作者:行者123 更新时间:2023-12-03 22:34:57 25 4
gpt4 key购买 nike

版本: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'
},
});

最佳答案

网络图片要求您设置高度/宽度样式 Prop 。

React Native Documentation .

Many of the images you will display in your app will not be available at compile time, or you will want to load some dynamically to keep the binary size down. Unlike with static resources, you will need to manually specify the dimensions of your image.


// GOOD
<Image source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
style={{width: 400, height: 400}} />

// BAD
<Image source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}} />

关于reactjs - react-native:未设置宽度或高度时不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40910421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com