我对 React-Native 和 Javascript 非常陌生,并且一直在努力学习。我试图将图像的宽度设置为屏幕尺寸除以 10。我设置了一个构造函数和一个具有屏幕宽度和高度的状态,但无法使用该状态来设置图像的宽度或高度。
constructor(props) {
super(props);
const { width, height } = Dimensions.get("window")
this.state = {
width,
height
}
}
如果我这样做...
<Image source={require('./my-icon.png')} style={{width: {this.state.width}, height: 40}}/>
它给我一个错误,说“this”是保留字。
最佳答案
我修好了。我想我犯了一个愚蠢的错误。我删除了括号并且它起作用了。
<Image source={require('./my-icon.png')} style={{width: this.state.width/10, height: 40}}/>
关于javascript - 将图像设置为相对于屏幕尺寸的尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44349574/