2017-06-03 223 views
1

我对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}}/> 

它给了我一个错误,指出“这”是一个保留字。

回答

1

我修好了。我想我犯了一个愚蠢的错误。我删除了括号,它的工作。

<Image source={require('./my-icon.png')} style={{width: this.state.width/10, height: 40}}/> 
相关问题