简体   繁体   English

uri图像未在React native Image视图中呈现

[英]uri image is not rendering in React native Image view

I am new to React native development and developing an android application using React Native. 我是React Native开发和使用React Native开发android应用程序的新手。 I have a profile page where I am trying to show name and contact detail like below. 我有一个个人资料页面,我试图在其中显示姓名和联系方式,如下所示。

return(
    <View style={{flex: 1}}>
      <ScrollView contentContainerStyle={styles.contentContainer}>
      <View style={styles.card}>
        <View style={styles.horizontalCard}>
        <Image
          style={{width: 34, height: 34}}
          source={{uri: 
       'http://test.abc.com/appdummyurl/images/mobile.png'}}
        />
          <Text style={styles.header}>{this.state.user_email}</Text>
        </View>

        <View style={styles.horizontalCard}>
        <Image
          style={{width: 34, height: 34}}
          source={{uri: 
      'http://test.abc.com/appdummyurl/images/images/profile.png'}}
        />
          <Text style={styles.header}>{this.state.user_no}</Text>
        </View>

        </View>    

    </ScrollView>
    <TouchableOpacity onPress={this.logOut}>
            <View style={styles.BottonCard}>
              <Text style={styles.Btntext}>LOG OUT</Text>
            </View>
          </TouchableOpacity>
  </View>
);

Everything is working fine except the first image is loading to first Image view and for the second Image its showing the blank space. 除了第一个图像正在加载到第一个图像视图,第二个图像显示空白处,一切正常。 Please help me to figure it out. 请帮我弄清楚。

Also please guide me how can I use a variable in the place of image url. 另外,请指导我如何使用变量代替图片网址。

It may be your network is slow or may be your image path is not correct or your server issue. 可能是您的网络速度较慢,或者图像路径不正确或服务器问题。 You have to test this case on any dummy image path from google. 您必须在google的任何虚拟图像路径上测试这种情况。 For example use this 例如使用这个

<Image
      style={{width: 100, height: 100}}
      source={{uri: 
   'https://www.planwallpaper.com/static/images/9-credit-1.jpg'
    }}/>

Also if you are in using local files be extra careful when you are using localhost on your links. 另外,如果您正在使用本地文件,则在链接上使用localhost时要格外小心。 Emulators may set a new localhost which would break your urls for them. 模拟器可能会设置一个新的本地主机,这将破坏您的URL。 In this case all you would have to do is to replace the word "localhost" with your LAN ip address. 在这种情况下,您要做的就是用您的LAN ip地址替换“ localhost”一词。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM