繁体   English   中英

来自URL的图像未在Android中显示为本机应用程序

[英]Images from URL not displaying in Android react native app

在移动设备上运行应用程序时,为什么没有显示图像? 我仅遵循了本教程,并添加了几行代码: https : //facebook.github.io/react-native/docs/getting-started.html

import React, {
  Component
} from 'react';

import {
  AppRegistry,
  Image,
  StyleSheet,
  Text,
  View
} from 'react-native';

var MOCKED_MOVIES_DATA = [
  {title: 'Title', year: '2015', posters: {thumbnail: 'http://i.imgur.com/UePbdph.jpg'}},
];

export default class AwesomeProject extends Component {
  render() {
    var movie = MOCKED_MOVIES_DATA[0];
    return (
      <View style={styles.container}>
        <Text>{movie.title}</Text>
        <Text>{movie.year}</Text>
        <Image source={{uri: movie.posters.thumbnail}} />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
});

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

设置width和height属性后,将显示图像。

<Image style={{width: 60, height: 60}} source={{uri: movie.posters.thumbnail}} />

尝试使用https代替http。 这可能是主要问题。

暂无
暂无

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

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