Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In React Native, how do I put a view on top of another view, with part of it lying outside the bounds of the view behind?

Tags:

react-native

I'm trying to make a layout as per below with React Native.

enter image description here

How do I specify the position of B relative to A?

With iOS Interface Builder and autoconstraints, this can very explicitly be done and is a breeze. It's not so obvious how one might achieve this with React Native.

like image 673
fatuhoku Avatar asked Jun 28 '15 15:06

fatuhoku


People also ask

How do you position a view in React Native?

position ​ position in React Native is similar to regular CSS, but everything is set to relative by default, so absolute positioning is always relative to the parent. If you want to position a child using specific numbers of logical pixels relative to its parent, set the child to have absolute position.

How do you make an overlay in React Native?

To add a transparent overlay in React Native, we can use the ImageBackground component. to add an ImageBackground with the source set to an object with the uri of the background image. And we add the backgroundImage style that sets opacity to 0.3 to add a transparent overlay over the image.


2 Answers

Add the following style to the "floating" view:

position: 'absolute' 

You may also need to add a top and left value for positioning.

like image 129
boredgames Avatar answered Sep 24 '22 17:09

boredgames


The above solutions were not working for me. I solved it by creating a View with the same background colour as the parent and added negative margin to move the image upwards.

<ScrollView style={{ backgroundColor: 'blue' }}>   <View     style={{       width: '95%',       paddingLeft: '5%',       marginTop: 80,       height: 800,     }}>     <View style={{ backgroundColor: 'white' }}>        <Thumbnail square large source={{uri: uri}} style={{ marginTop: -30 }}/>       <Text>Some Text</Text>     </View>   </View> </ScrollView> 

and I got the following result.

enter image description here

like image 38
Abdul Karim Khan Avatar answered Sep 25 '22 17:09

Abdul Karim Khan