React native 为什么我的图像(和子组件)没有在React Native上显示ImageBackground?
我对应用程序上显示的图像有问题。通过搜索结果,我主要看到的解决方案是,高度和宽度是必需的,但我已经实现了,没有结果 我已经多次查看了路线,没有发现任何问题 最后,我认为这可能与图像有关。我已经改变了大小,它与React native 为什么我的图像(和子组件)没有在React Native上显示ImageBackground?,react-native,background-image,react-native-ios,React Native,Background Image,React Native Ios,我对应用程序上显示的图像有问题。通过搜索结果,我主要看到的解决方案是,高度和宽度是必需的,但我已经实现了,没有结果 我已经多次查看了路线,没有发现任何问题 最后,我认为这可能与图像有关。我已经改变了大小,它与标签一起工作。然而,我需要它是一个背景图像 现行代码 从“React”导入React 从“react native”导入{View,Text,StyleSheet,ImageBackground}; 从“@expo/vector icons”导入{MaterialCommunityIcons
标签一起工作。然而,我需要它是一个背景图像
现行代码
从“React”导入React
从“react native”导入{View,Text,StyleSheet,ImageBackground};
从“@expo/vector icons”导入{MaterialCommunityIcons}
导出默认功能标题屏幕(){
返回(
测试
{/* */}
)
}
const styles=StyleSheet.create({
背景图片:{
弹性:1,
宽度:“100%”,
高度:“100%”,
}
});
文件夹布局
- 资产
--图像
---title_background.png - 组件
--TitleScreen.js
- 回答!答案是将flex:1添加到父视图容器中-对于遇到相同问题的用户。尝试将
flex:1
添加到view
哦,我的天哪,成功了。非常感谢。上面的例子没有说明这一点,所以我错过了。谢谢你!
import React from 'react'
import { View, Text, StyleSheet, ImageBackground } from 'react-native';
import { MaterialCommunityIcons } from '@expo/vector-icons'
export default function TitleScreen () {
return (
<View>
<ImageBackground
source={require('../assets/images/title_background.png')}
style={styles.backgroundImage}
imageStyle={{resizeMode: 'cover'}}
>
<Text>testing</Text>
{/* <MaterialCommunityIcons
name={'cards-outline'}
size={100}
/> */}
</ImageBackground>
</View>
)
}
const styles = StyleSheet.create({
backgroundImage: {
flex: 1,
width: '100%',
height: '100%',
}
});