我想把汽车图像放在背景图像上,就是这样。
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')
好的,但为什么它需要&#39; style.width&#39;甚至我使用 resizeMode:&#39; cover&#39; 我还在样式对象中设置宽度和高度属性仍然是相同的错误..我该如何解决这个问题?