【发布时间】:2018-08-17 10:22:37
【问题描述】:
如屏幕截图所示,我想在视图上显示隐藏在视图后面的个人资料图像。我正在使用 React-native 实现它。
顶部红色视图,其中添加个人资料图片。在其下添加另一个带阴影的视图。
<Content style={styles.content}>
<View style={styles.topView} transparent>
<View style={styles.profileImageView}>
<Image
style={styles.profileImage}
source={require("../Images/avatar.png")}
/>
</View>
</View>
<View style={styles.middleView} transparent>
<View />
<View />
</View>
</Content>
CSS 代码
content: {
flex: 1,
backgroundColor: "#f5f6f8"
},
topView: {
marginTop: 30,
marginLeft: 15,
width: "100%",
height: 40,
backgroundColor: "red"
},
profileImageView: {
width: 100,
height: 100,
marginLeft: 30,
borderRadius: 5,
backgroundColor: "yellow",
position: "absolute"
},
profileImage: {
width: "100%",
height: "100%",
position: "absolute"
// marginLeft: 45,
// marginTop: 30,
// borderRadius: 5
},
middleView: {
width: 360,
height: 346,
marginTop: 14,
marginLeft: 15,
borderRadius: 10,
backgroundColor: "#ffffff",
shadowColor: "#B8B8B8",
shadowOffset: {
width: 0,
height: 10
},
shadowRadius: 20,
shadowOpacity: 1
}
我已经尝试过 position:"absolute" 和 overlay:"hidden"。但是,没有什么对我有用。
希望有更好的解决方案。 提前致谢。
【问题讨论】:
-
你玩过 z-index。为 profile 图像提供比视图更高的 z-index。 z-index 确实需要一个位置。
标签: html ios css react-native