javascript - zIndex 在组件中不起作用
问题描述
我有一个蓝色标题,我想通过动画事件在另一个视图中参与其中。但是在我执行动画功能之前,我手动设置了 zIndexes,并且知道它根本不起作用!意味着当我给组件的属性赋予 1 或 100 或其他值时,什么都不会改变zIndex
:(
<View style={{ flex: 1 }}>
<Animated.View style={{
position: 'absolute',
top: 0,
left: 0, right: 0,
backgroundColor: 'lightskyblue',
height: headerHight,
zIndex: 1,//Look here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
alignItems: 'center',
}}>
<Animated.View style={{ position: 'absolute', top: titleTop }}>
<Text style={{ fontWeight: 'bold', fontSize: 26, paddingLeft: 10 }}>Iman Salehi</Text>
</Animated.View>
</Animated.View>
<ScrollView style={{ flex: 1 }}
scrollEventThrottle={16}
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { y: this.state.scrollY } } }]
)}>
<Animated.View style={{
height: profileImageHight,
width: profileImageHight,
borderRadius: PROFILE_IMAGE_MAX_HIGHT / 2,
borderColor: 'white',
borderWidth: 3,
overflow: 'hidden',
marginTop: profileImageMarginTop,
zIndex:0, //Look here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
marginLeft: 10,
}}>
<Image source={require('./assets/avatar.jpg')} style={{ flex: 1, width: null, height: null}} />
</Animated.View>
<Text style={{ fontWeight: 'bold', fontSize: 26, paddingLeft: 10 }}>Iman Salehi</Text>
<View style={{ height: 1000 }}></View>
</ScrollView>
</View>
就像你在上面看到的:有两个组件有 zIndex。因此,zIndex:1
预计会采用另一个,但在运行时它们没有变化。
解决方案
尝试使用 zIndex 和绝对位置进行高程。
在要显示在前层的组件上应用以下样式
style={{ position: 'absolute', elevation: 100,zIndex:100, //other style }}
让我知道是否仍然面临问题
推荐阅读
- c++ - 我收到此错误“在 0x7BE7B103 (msvcp140d.dll) 处引发异常:运行我的代码时
- javascript - 我在反应中遇到了一个 npm 命令错误。“找不到主模块中的错误:错误:无法解决......”
- html - 从 html 视图渲染 pdf 文件以将其作为图像预览显示在网页上
- c# - Newtonsoft 忽略序列化的属性
- opengl - OPENGL 从地形对象获取高度
- angular - “预计在 'ProxyZone' 中运行,但没有找到。” 开玩笑的
- mysql - 简单的 MySQL 更新查询不起作用 - mysql 错误 1064
- c# - C# Winform TreeView BeforeSelect 事件触发两次
- google-bigquery - 连接到 Google Cloud Platform 上的 Big Query 时,Power BI 报告很慢
- php - Laravel:动作@index未定义