繁体   English   中英

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

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

我想为我的应用程序设置背景图像。 当我运行expo start ,图像不显示。 这是我的组件:

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",
  },
});

我错过了什么? 我感谢任何帮助

根据反应本机文档:

“请注意,您必须指定一些宽度和高度样式属性。”

https://reactnative.dev/docs/imagebackground

暂无
暂无

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

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