0

我正在尝试在 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.png存在。 在此处输入图像描述

这是我得到的输出。 在此处输入图像描述

这是我的 bg.png 在此处输入图像描述

我找不到这有什么问题。一切似乎都很好,而且我没有收到任何错误消息。请帮忙

4

1 回答 1

2

这是博览会的链接。

对于大图像,位图出现内存不足的情况似乎在 android 中发生了崩溃。

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

有关更多信息,请查看此链接

于 2018-04-18T06:36:48.237 回答