我想把汽车图像放在背景图像上,就是这样.
import React,{ Component } from 'react'; import { ... Animated,ImageBackground } from 'react-native'; export default class App extends Component { render() { return ( <ImageBackground imageStyle={styles.container} source={require('./src/assets/img/road1.jpg')}> <Animated.Image style={styles.car} source={require('./src/assets/img/car2.png')}> </Animated.Image> </ImageBackground> ); } } const styles = StyleSheet.create({ container: { flex: 1,position: 'relative',resizeMode: 'cover' },car:{ position:'absolute',width:100,height:50 } });
Type error:undefined is not an object(evaluating 'style.width')
好吧,但为什么它需要’style.width’,即使我使用resizeMode:’cover’
我还在样式对象中设置宽度和高度属性仍然是相同的错误..我该如何解决这个问题?
您的错误来自ImageBackground.js.
原文链接:https://www.f2er.com/react/443134.html您正在为ImageBackground提供容器样式作为prop,它需要在那里存在宽度.
您通过无效的prop imageStyle提供样式.它应该作为样式提供
尝试:
<ImageBackground style={styles.container} source={require('./src/assets/img/road1.jpg')}> <Animated.Image style={styles.car} source={require('./src/assets/img/car2.png')}> </Animated.Image> </ImageBackground>