Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place an Image on top of other Image in React Native?

Tags:

I placed an Image as a root node in order to make it a background for my View. But it appears that all others image become invisible... Is it any way to place an image on top of the background using built-in components, without any plugins?
In the following code sample landing-background is used as a background, my logo image is visible, but only if background is removed.
Text is showing on top of the background without any concerns...

    <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'       }     }); 
like image 488
Федор Усаков Avatar asked Nov 17 '15 15:11

Федор Усаков


People also ask

How do I add a picture on top of react-native?

Open App. js and add the following code: import { StatusBar } from "expo-status-bar"; import React from "react"; import { StyleSheet, Text, View, ImageBackground } from "react-native"; const staticImage = require("./src/assets/static-image. png"); export default function App() { return ( <View style={styles.

How do you overlap icons in react-native?

Add the css property, position: 'absolute' to the element you want to overlap.


2 Answers

Rather than wrapping your content in the <Image>, I think you would be better off wrapping that in an absolutely positioned element and having that stretch to cover the screen.

<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'   } }); 
like image 108
Chris Schmitz Avatar answered Oct 27 '22 01:10

Chris Schmitz


I have the same issue, I used an <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> 
like image 45
amirreza karimi Avatar answered Oct 26 '22 23:10

amirreza karimi