简体   繁体   English

本地图片在reactnative中不显示

[英]The local image is not displayed in the reactnative

I'm new to reactnative.我是 Reactnative 的新手。 Whatever I do, I do not know why it does not show local images.无论我做什么,我都不知道为什么它不显示本地图像。 I changed the photo, I changed the location of the file, etc., but it did not work.我更改了照片,更改了文件的位置等,但都没有用。

import { StatusBar } from 'expo-status-bar';
import { Image, StyleSheet, Text, View } from 'react-native';

export default function App() {
  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <Image  source={require('./assets/icon.png')} />
      <StatusBar style="auto" />
    </View>
  );
}

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

I don't think the problem is the location of your image.我认为问题不在于您的图片位置。 You should specify the size of the image.您应该指定图像的大小。 style={{ width: 40, height: 40 }}

 <View style={styles.container}>
  <Text>Open up App.js to start working on your app!</Text>
  <Image style={{ width: 40, height: 40 }} source={require('./assets/icon.png')} />
  <StatusBar style="auto" />
</View>

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

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