Фед*_*ков 14 image ios react-native
我将一个Image作为根节点放置,以使其成为我的View的背景.但似乎所有其他图像都变得不可见......是否可以使用内置组件将图像置于背景之上,而无需任何插件?
在下面的代码中,示例landing-background
用作背景,我的logo
图像是可见的,但仅在背景被删除时才可见.Text
在没有任何顾虑的情况下显示在背景之上...
<View style={styles.container}>
<Image source = {require('./img/landing-background.jpg')}
resizeMode = 'cover' style = {styles.backdrop}>
<View style = {styles.overlay}>
<Text style = {styles.headline}>It should appear in front of the Background Image</Text>
<Image style = {styles.logo} source = {require('./img/logo.png')} />
</View>
</Image>
</View>
var styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
},
overlay: {
opacity: 0.5,
backgroundColor: '#000000'
},
logo: {
backgroundColor: 'rgba(0,0,0,0)',
width: 160,
height: 52
},
backdrop: {
flex:1,
flexDirection: 'column'
},
headline: {
fontSize: 18,
textAlign: 'center',
backgroundColor: 'rgba(0,0,0,0)',
color: 'white'
}
});
Run Code Online (Sandbox Code Playgroud)
Chr*_*itz 26
<Image>
我认为你最好不要将你的内容包装在一个absolute
定位的元素中,而是用这种拉伸覆盖屏幕.
<View style={styles.container}>
<View style = {styles.backgroundContainer}>
<Image source = {require('./img/landing-background.jpg')} resizeMode = 'cover' style = {styles.backdrop} />
</View>
<View style = {styles.overlay}>
<Text style = {styles.headline}>It should appear in front of the Background Image</Text>
<Image style = {styles.logo} source = {require('./img/logo.png')} />
</View>
</View>
var styles = StyleSheet.create({
backgroundContainer: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
},
container: {
flex: 1,
alignItems: 'center',
},
overlay: {
opacity: 0.5,
backgroundColor: '#000000'
},
logo: {
backgroundColor: 'rgba(0,0,0,0)',
width: 160,
height: 52
},
backdrop: {
flex:1,
flexDirection: 'column'
},
headline: {
fontSize: 18,
textAlign: 'center',
backgroundColor: 'black',
color: 'white'
}
});
Run Code Online (Sandbox Code Playgroud)
小智 5
我有同样的问题,我使用了 <ImageBackground>
<View style={{height: 55,width: 55,justifyContent: 'center',alignItems: 'center'}}>
<ImageBackground source={{uri:this.state.image1}} style={{height: 50,width: 50}}>
<View style={{flex: 1,justifyContent: 'flex-end',alignItems: 'flex-start'}}> //here you can change position of image with justifyContent and alignItems
<Image
source={ {uri:this.state.image2}}
style={{width: 20 , height: 20 ,alignItems: 'center',justifyContent: 'center',borderWidth: 1,borderColor: '#fff',borderRadius: 30}} />
</View>
</ImageBackground>
</View>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19906 次 |
最近记录: |