如何在本机应用程序中显示图像预览?

时间:2018-01-15 04:54:04

标签: android ios image react-native preview

我可以知道如何在React Native应用中显示图像预览吗?在iOS中,我能够显示它是否是一个http网址,但在Android平台上我无法查看图像,如下面的屏幕截图所示:

Android中的Running React Native App:

enter image description here

iOS平台中的图片预览:

enter image description here

在代码中,附件字段等于this.state.attachment,因此可以看到http网址,但是当我将其与图像连接时,图像预览为空白。但是,如果我在iOS中硬编码确切的http url地址,它就可以显示图像。

//in iOS this one can show the image but Android cannot
let Image_Http_URL = { uri : 'http://localhost:3000/api/containers/container/download/FMS-SiteIcon_v2.jpg'};

//this one is both cannot but in url can show the http url address
let Image_Http_URL = { uri : 'this.state.attachment' };

<Image
 style={{width: 200, height: 200}}
 source={Image_Http_URL}
/>

<FloatLabelTextInput
 onChangeText={(attachment) => {
 this.setState({attachment})
 }}
value={this.state.attachment}
editable={false}
placeholder="Attachment"
style={styles.input}/>

请帮助和谢谢。

1 个答案:

答案 0 :(得分:0)

this.state.attachment不应包含在字符串中,请尝试{ uri : this.state.attachment };{ uri : {this.state.attachment} };