React native 如何在React Native中将图像设置为窗体的背景?
我一直在做一个表格,我需要得到一个背景图像,使它看起来更漂亮。当我在图像标记中使用表单组件时,它显示以下错误 我给下面的代码,我用React native 如何在React Native中将图像设置为窗体的背景?,react-native,styles,background-image,React Native,Styles,Background Image,我一直在做一个表格,我需要得到一个背景图像,使它看起来更漂亮。当我在图像标记中使用表单组件时,它显示以下错误 我给下面的代码,我用 import React,{Component} from 'react' import {Image,View,Dimensions,ImageBackground} from 'react-native' let {height,width}=Dimensions.get('window') class DearImage extends Component
import React,{Component} from 'react'
import {Image,View,Dimensions,ImageBackground} from 'react-native'
let {height,width}=Dimensions.get('window')
class DearImage extends Component {
render() {
return (
<View >
<Image source={require('../drawable/Auntie.jpeg')}
width={width}
height={height} >
{this.props.children}
</Image>
</View>
);
}
}
export default DearImage;
import React,{Component}来自“React”
从“react native”导入{Image,View,Dimensions,ImageBackground}
设{height,width}=Dimensions.get('window')
类图像扩展组件{
render(){
返回(
{this.props.children}
);
}
}
导出默认图像;
render(){
返回(
{this.props.children}
)
}
您的错误显示您需要将图像设置为绝对位置,为避免此问题,您可以使用图像背景。并且图像标记不能直接包含任何子标记,请使用视图,就像下面的代码一样使用,它将适用于您
import React,{Component} from 'react'
import {Image,View,Dimensions,ImageBackground} from 'react-native'
let {height,width}=Dimensions.get('window')
class DearImage extends Component {
render() {
return (
<ImageBackground
source={require('../drawable/Auntie.jpeg')}
style={{
backgroundColor: '#ccc',
flex:1,
width: '100%',
height: '100%',
justifyContent: 'center',
}} >
<View style={{flex:1,position:"absolute", backgroundColor: 'transparent', }}>
{this.props.children}
</View>
</ImageBackground >
)
}
}
export default DearImage;
import React,{Component}来自“React”
从“react native”导入{Image,View,Dimensions,ImageBackground}
设{height,width}=Dimensions.get('window')
类DearImage扩展组件{
render(){
报税表(
{this.props.children}
)
}
}
导出默认图像;
使用图像背景而不是图像
import React,{Component} from 'react'
import {Image,View,Dimensions,ImageBackground} from 'react-native'
let {height,width}=Dimensions.get('window')
class DearImage extends Component {
render() {
return (
<ImageBackground source={require('../drawable/Auntie.jpeg')}
width={width}
height={height}
style = {{flex:1}}>
{this.props.children}
</ImageBackground>
)
}
}
export default DearImage;
import React,{Component}来自“React”
从“react native”导入{Image,View,Dimensions,ImageBackground}
设{height,width}=Dimensions.get('window')
类图像扩展组件{
render(){
返回(
{this.props.children}
)
}
}
导出默认图像;
如果你不介意这个标签是干什么的,我看不到关于它的任何文档,也看不到你错误导入的任何代码,这是不需要的,Hari,你只需要导入图像没有像ImageBackground这样的标签是的,我试过了,它不起作用。同样的错误再次出现在我们面前。
import React,{Component} from 'react'
import {Image,View,Dimensions,ImageBackground} from 'react-native'
let {height,width}=Dimensions.get('window')
class DearImage extends Component {
render() {
return (
<ImageBackground source={require('../drawable/Auntie.jpeg')}
width={width}
height={height}
style = {{flex:1}}>
{this.props.children}
</ImageBackground>
)
}
}
export default DearImage;