简体   繁体   English

React-Native | 我无法覆盖 bg 图像

[英]React-Native | I can't get the bg image to cover

I'm trying to fit my background image to cover the whole app but its not, even though i've tested most of similar threads here so any help is appreciated.我试图让我的背景图像覆盖整个应用程序,但它不是,即使我已经在这里测试了大多数类似的线程,所以任何帮助表示赞赏。

I've made some changes to the original source and added an arrow towards the left edge of the image that i was hoping to have at the edge when i open up the EXPO app on my phone, but i only see a few pixels of the arrow at the left edge.我对原始来源进行了一些更改,并在图像的左边缘添加了一个箭头,当我在手机上打开 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"
}

try this:-尝试这个:-

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;

It is working fine.它工作正常。

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

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