[英]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.