React-Native不显示背景图像

时间:2018-04-17 16:03:59

标签: react-native background-image imagebackground

我试图在React-Native中设置背景图片,但它没有出现在我的屏幕上。但是,<ImageBackground></ImageBackground>中的文本正在显示。 这是我的代码:

import React, { Component } from 'react';
import { View, ImageBackground, Text, StyleSheet } from 'react-native';

type Props = {};
export default class App extends Component {
  render() {
    return (
    <ImageBackground style={styles.container} source={require("./Assets/bg.png")}>
        <Text>Inside</Text>
    </ImageBackground>
    );
  }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        width: '100%',
        height: '100%'
    }
});

以下是我的目录结构。您可以看到存在bg.pngenter image description here

这是我得到的输出。 enter image description here

这是我的bg.png enter image description here

我无法找到这个有什么问题。一切似乎都没问题,我也没有收到任何错误消息。请帮忙

1 个答案:

答案 0 :(得分:1)

以下是expo的链接。

在大型图像中,似乎发生了崩溃,位图变得内存不足。

因此,解决方法是调整大小图像并使用它。

有关详情,请查看此link

相关问题