问题描述
我正在尝试让我的背景图片覆盖整个应用程序,但它没有,尽管我已经在这里测试了大多数类似的线程,因此感谢任何帮助。
我对原始来源进行了一些更改,并向图像的左边缘添加了一个箭头,当我在手机上打开 EXPO 应用程序时,我希望该箭头位于边缘,但我只看到了一些左边缘箭头的像素。
**app.js**
function HomeScreen() {
return (
<imagebackground source={require('./assets/bgImage.jpg')} style={styles.bgImage}>
<View>
<Text>Home Screen</Text>
</View>
</imagebackground>
);
}
bgImage: {
flex: 1,width: null,height: null,resizeMode: 'cover',justifyContent: 'center',alignItems: "center"
}
解决方法
试试这个:-
import React from 'react';
import { ImageBackground,View,Text } from 'react-native';
const HomeScreen = () => {
return (
<ImageBackground source={require('../assets/apple.jpg')}
style={{
position: "absolute",top: 0,left: 0,bottom: 0,right: 0,flex: 1,alignItems: "center"
}}>
<View style={{
width: '90%',height: 200,backgroundColor: "red",justifyContent: "center",alignItems: "center",}}>
<Text>Home Screen</Text>
</View>
</ImageBackground>
);
}
export default HomeScreen;
一切正常。