我想在我的 native 应用程序中使用背景图片,
图像比屏幕小,所以我必须拉伸(stretch)它。
但如果图像是 则不起作用从 Assets 包加载
var styles = StyleSheet.create({
bgImage: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'stretch',
resizeMode: 'stretch',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
}
});
<Image source={require('image!background')} style={styles.bgImage}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
</Image>
它看起来像这样:
![enter image description here](https://i.sstatic.net/Ppm9Z.png)
但是,它适用于远程图像,通过
source={{uri: 'background-image-uri'}}
:![enter image description here](https://i.sstatic.net/RzNYq.png)
最佳答案
对我来说使用 undefined
而不是 null
值(value)。在 typescript 环境下,会提示 not assignable
bgImage: {
flex: 1,
width: undefined,
height: undefined,
resizeMode: 'stretch',
},
关于react-native - 如何在 React Native 中将静态图像拉伸(stretch)为背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30273624/