I have the following React Native code:
<View style={itemStyle.content}>
<Text
style={textIndexStyle.content}>
{this.props.element["indexNumber"] + 1}
</Text>
<Image
source={{uri: someUri}}
style={imageStyle.content}
/>
</View>
With this styling:
const imageStyle = StyleSheet.create({
content:{
alignSelf: 'flex-end',
justifyContent:'flex-end',
backgroundColor: '#7CFC00',//light green
width: '100%',
height: '75%',
resizeMode: 'contain',
flexBasis: '50%'
}
});
const textIndexStyle = StyleSheet.create({
content:{
// position: 'absolute',
// transform: ('50%', '50%'),
alignSelf: 'flex-start',
backgroundColor: '#ffa500',
textAlign: 'center',
fontSize: 20,
fontWeight: 'bold',
width: getPercentageOfSmallest(0.07),
height: getPercentageOfSmallest(0.07)
}
});
const itemStyle = StyleSheet.create({
content:{
flexDirection:'column',
alignItems:'flex-start',
justifyContent:'flex-start',
backgroundColor: '#9400D3',//purple
paddingRight: '10%',
// marginTop: -50,
width: getPercentageOfWidth(0.7),
}
});
The result is this:
I would like the orange box with the number to be placed inside the image container(on the green background), rather than on top of it(on the purple background).
As it can be seen in the commented code, I tried:
- setting a negative margin for the outer container
- making the position absolute and then translating the orange box
However, that didn't work.
Any idea how I can make the orange box with the text to be put on top of the image?