【发布时间】:2019-04-02 10:45:11
【问题描述】:
当我从状态调用源时,ImageBackground 不显示图像。
我尝试使用条件语句,例如起初可触摸的不透明度,但不能再次工作。
state = {
color1: "../images/yellow-orb.png",
color2: "../images/yellow-orb.png",
}
<TouchableOpacity onPress={() => this.questSelect(1)}>
{this.state.color1 ? (
<ImageBackground
source={{ uri: this.state.color1 }}
style={styles.icon2}
>
<Text>1</Text>
</ImageBackground>
) : (
null
)}
</TouchableOpacity>
<TouchableOpacity onPress={() => this.questSelect(2)}>
<ImageBackground
source={{ uri: this.state.color2 }}
style={styles.icon2}
>
<Text>2</Text>
</ImageBackground>
</TouchableOpacity>
在模拟器中,我可以看到像 1 2 3 .. 这样的文本,但没有图像。
【问题讨论】:
-
你能分享一下你的 ImageBackground 的样式吗?
-
icon2: { 高度:Dimensions.get("window").width / 9,宽度:Dimensions.get("window").width / 9,marginTop:Dimensions.get("window" ).width / 60 },
标签: react-native touchableopacity imagebackground