【发布时间】:2018-06-28 14:16:08
【问题描述】:
我想让一个元素重叠到本机反应的图像上。我是 react native 的新手,但可以在 CSS 中用 3 行代码做到这一点:
相对位置的容器。 绝对位置+底部的元素:20px。
这是我的 react native 代码和它的截图。
<ScrollView style={styles.container}>
<Image
style={styles.profileImage}
source={{uri: blabla}}
/>
<View style={styles.iconContainer}>
<ActionIcon
name={'mode-edit'}
color={colorBrand}
onPress={() => console.log('test')}
/>
</View>
<List containerStyle={styles.list}>
<ListItem
title={'Account Settings'}
/>
<ListItem
title={'Notifications'}
/>
<ListItem
title={'Terms & Conditions'}
/>
<ListItem
title={'Privacy Policy'}
/>
<ListItem
title={'Log Out'}
/>
</ScrollView>
和样式表:
const styles = StyleSheet.create({
container: {
flex: 1
},
profileImage: {
height: 250
},
list: {
borderTopWidth: 0,
flex: 1,
marginTop: 0
},
iconContainer: {
alignSelf: 'flex-end',
right: 10,
bottom: 40,
marginBottom: -60,
zIndex: 1
}
})
所以它看起来像:
所以它看起来就像我想要的一样。但我不喜欢那个zIndex,也不喜欢那个消极的bottomMargin。
我首先尝试在相对位置使用 iconContainer 的容器,然后在绝对位置使用 iconContainer。但是要显示它,您必须设置一个高度。然后你有一个空白的全宽和设置的高度,右侧的图标。这会将列表向下推并添加一个大空白。
还有其他选择吗?
干杯
【问题讨论】:
标签: css react-native flexbox