// Declare a varible here...
const img = require('./asd.png')
// Example of a network image
const networkImage = "https://images.pexels.com/photos/799443/pexels-photo-799443.jpeg"
const [image, setImage] = useState(img) // Use it here like this
// Static Image Usage
<ImageBackground
source={image}
style={{ flex: 1, resizeMode: 'cover', justifyContent: 'center' }}>
</ImageBackground>
// Network Image Usage
<ImageBackground
source={{uri : networkImage}}
style={{ flex: 1, resizeMode: 'cover', justifyContent: 'center' }}>
</ImageBackground>
这是正确的使用方法ImageBackground
检查此小吃以查看工作示例
此外,请查看文档以获取更多帮助。
正如文档所说,
// GOOD (this is also correct)
<Image source={require('./my-icon.png')} />;
// BAD (this is wrong...)
var icon = this.props.active
? 'my-icon-active'
: 'my-icon-inactive';
<Image source={require('./' + icon + '.png')} />;
// GOOD (this is correct)
var icon = this.props.active
? require('./my-icon-active.png')
: require('./my-icon-inactive.png');
<Image source={icon} />;