Css 为什么在我的react原生项目中不应用背景图像
在应用程序文件夹中,我有两个文件夹屏幕和资源,我正在提供正确的路径,但背景图像未应用于模拟器Css 为什么在我的react原生项目中不应用背景图像,css,react-native,Css,React Native,在应用程序文件夹中,我有两个文件夹屏幕和资源,我正在提供正确的路径,但背景图像未应用于模拟器 您需要将图像标记放在视图标记之间,以便react-native在模拟器上呈现图像,例如: 在您的应用程序中 const App = (props) => { return ( <View style={styles.container} > <Image style= { styles.backgroundImage } source=>
您需要将图像标记放在视图标记之间,以便react-native在模拟器上呈现图像,例如: 在您的
应用程序中
const App = (props) => {
return (
<View style={styles.container} >
<Image style= { styles.backgroundImage } source=>
</Image>
<View style={styles.logoContainer}>
<Text style={styles.logoText}>
Hello
</Text>
<Text style={styles.logoDescription}>
Hello world
</Text>
</View>
</View>
);
}
在您的例子中,您使用的是ImageBackground
,应该是这样的:
const App = (props) => {
return (
<View style = { styles.container } >
<ImageBackground style= { styles.backgroundImage } source= >
<View style= { styles.logoContainer }>
<Text style = { styles.logoText }>
Hello
</Text>
<Text style = { styles.logoDescription }>
Hello world
</Text>
</View>
</ImageBackground>
</View>
);
}
const-App=(道具)=>{
返回(
你好
你好,世界
);
}
用视图包装图像背景:
<View style={styles.imgWrap}>
<ImageBackground
source={require('assets/img/avatar-placeholder.png')}
style={styles.img}
/>
</View>
我只有一个元素需要在背景图像中包装吗?不要考虑你有多少元素,图像标签或背景图像标签,NeeDeI没有注意到你想要全屏,所以使用这个:img封包:{flex:1,},img:{flex:1,ResiZeMod:“封面”,}请不要使用代码和错误消息的屏幕截图。屏幕截图在移动设备上很难阅读,无法搜索,我们都无法复制、粘贴和运行图像。问问题时请继续阅读?
<View style={styles.imgWrap}>
<ImageBackground
source={require('assets/img/avatar-placeholder.png')}
style={styles.img}
/>
</View>
const styles = StyleSheet.create({
imgWrap: {
width: 100,
height: 100,
overflow: 'hidden',
borderRadius: 50,
},
img: {
flex: 1,
resizeMode: "contain",
justifyContent: "center"
}
})