【发布时间】:2018-04-17 16:03:58
【问题描述】:
我正在尝试在 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%'
}
});
我找不到这有什么问题。一切似乎都很好,而且我没有收到任何错误消息。请帮忙
【问题讨论】:
-
你也可以添加你的图片吗?
-
@PritishVaidya 请查看我编辑的答案,我刚刚添加了我试图设置为背景的图像
-
由于 android 中的大画布图像渲染,应用程序崩溃了,所以我将它的大小调整为 25% 并且它工作了。
-
但在我的情况下,应用程序没有崩溃,我也没有收到任何错误。只有图像没有出现。就是这样
-
查看这个link android 和 ios
标签: react-native background-image imagebackground