为什么我的图像(和子组件)没有在 React Native 上以 ImageBackground 显示?
Why is my image (and child components) not showing with ImageBackground on React Native?
我对刚出现在应用程序上的图像有疑问。通过搜索结果,我看到的解决方案大多是要求高度和宽度并且缺少,但我已经实现了没有结果。
我多次查看路线,没有发现任何问题。
最后,我认为这可能与图像有关。我已经改变了大小,它与 <Image />
标签一起工作。但是,我需要它作为背景图片。
当前代码
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%',
}
});
文件夹布局
- 资产
-- 图片
--- title_background.png
- 组件
-- TitleScreen.js
已回答!答案是将 flex: 1 添加到父视图容器 - 对于那些 运行 遇到同样问题的人。
我对刚出现在应用程序上的图像有疑问。通过搜索结果,我看到的解决方案大多是要求高度和宽度并且缺少,但我已经实现了没有结果。
我多次查看路线,没有发现任何问题。
最后,我认为这可能与图像有关。我已经改变了大小,它与 <Image />
标签一起工作。但是,我需要它作为背景图片。
当前代码
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%',
}
});
文件夹布局
- 资产
-- 图片
--- title_background.png - 组件
-- TitleScreen.js
已回答!答案是将 flex: 1 添加到父视图容器 - 对于那些 运行 遇到同样问题的人。