简体   繁体   English

ImageBackground 在 react native + expo 中不显示本地图像

[英]ImageBackground don't show local image in react native + expo

I want to set an background image to my app.我想为我的应用程序设置背景图像。 When I run expo start the image dosen't show.当我运行expo start ,图像不显示。 this its my component:这是我的组件:

import React from "react";
import { StyleSheet, Text, View, ImageBackground } from "react-native";
import { Asset } from "expo-asset";

export default function App() {
  return (
    <View style={styles.container}>
      <ImageBackground
        source={{
          uri: Asset.fromModule(require("./images/background.png")).uri,
        }}
        style={styles.image}
      ></ImageBackground>
    </View>
  );
}

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

what I missed?我错过了什么? I appreciate any help我感谢任何帮助

According to the react native documentation:根据反应本机文档:

"Note that you must specify some width and height style attributes." “请注意,您必须指定一些宽度和高度样式属性。”

https://reactnative.dev/docs/imagebackground https://reactnative.dev/docs/imagebackground

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

相关问题 React-native 博览会中 ImageBackground 上方的 LinearGradient - LinearGradient above ImageBackground in react-native expo ImageBackground 不会呈现本机反应 - ImageBackground won't render react native React Native Expo:将 Expo ImagePicker 图像保存到本地文件夹时遇到问题 - React Native Expo: Trouble Saving an Expo ImagePicker image to a local folder 反应不显示ImageBackground包装器内的本机文本(带有图像) - React Native Text inside ImageBackground wrapper is not displaying (With Image) react-native中如何使用ImageBackground设置屏幕背景图片 - How to use ImageBackground to set background image for screen in react-native React native,ImageBackground 检查图像在导航到页面之前已加载 - React native, ImageBackground check image has loaded before navigating to page 无法在 expo react native 中从 url 下载图像到本地目录 - Unable to download image to local directory from url in expo react native Expo React Native,如何选择从 expo 图像选择器获得的默认本地图像或用户图像 - Expo React Native, How to pick default local images or user image obtained from expo image picker 当我从数据库中获取图像文件路径时,React Native 不显示图像 - React Native don't show image when I fetch image file path from database React Native Expo 图像大小调整 - React Native Expo Image Resizing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM