react-native - react native - 仅覆盖在某些组件之上
问题描述
我正在尝试显示一个简单的叠加层,但仅限于某些组件。
示例代码:
<Animated.View style={{ flex: 1 }}>
<Text style={ [{zIndex: 0}, styles.titleText] }>Title under overlay</Text>
<Animated.View style={ [styles.overlay] } />
<View style={{ zIndex: 2, flex: 1, justifyContent: 'center' }}>
<Text style={{ zIndex: 2, fontSize: 32, fontWeight: 'bold', color: '#ffffff', textAlign: 'center' }}>Subtitle above overlay</Text>
<Text style={ [{ zIndex: 0 }, styles.descriptionText] }>Text under overlay</Text>
<Text style={ [{ zIndex: 0 }, styles.descriptionText] }>Text above overlay</Text>
</View>
</Animated.View>
如前所述,我需要 Overlay 上面的一些组件和它下面的其他组件。
现在,在覆盖视图之后用代码编写的所有组件都位于覆盖之上。我特别希望说“覆盖下的文本”的组件出现在覆盖下,但其他文本应该在上面。
我该怎么做?zIndex 没有按照我想要的方式工作。
解决方案
您可以通过以下方式组合position: 'absolute'
和添加叠加层。zIndex
<View style={styles.container}>
<View style={{position: 'absolute', backgroundColor: 'transparent', top: 0, bottom: 0, right: 0, left: 0, zIndex: 0}} /> //... Here is the overlay
<View style={{backgroundColor: 'red', position: 'absolute', top: 0, bottom: 200, right: 0, left: 0, zIndex: 1}} >
// Set the elements over the overlay here
</View>
<View style={{backgroundColor: 'blue', position: 'absolute', top: 0, bottom: 100, right: 0, left: 0, zIndex: -1}} >
// Set the elements under the overlay here
</View>
</View>
这是样品小吃演示
推荐阅读
- sql - LINQ 不包含“联合”的定义
- glsl - 为什么在光线追踪器中方向是从球心到光线的原点?
- java - 尝试在空对象引用上调用虚拟方法 'android.view.SurfaceHolder android.view.SurfaceView.getHolder()'
- protractor - 当量角器脚本失败时,我们可以发送一封电子邮件,并在命令提示符中显示电子邮件内容作为错误
- java - 如何使用 Spring MVC 上传 Excel 文件?
- c - 我想将一个数组从我的主要方法传递给我的函数(min),以便可以在函数(min)中计算最小值
- c# - 时间:2019-01-10 标签:c#multiplyopeningwindowsform
- google-analytics - 使用谷歌分析创建用户个人资料
- listbox - 当列表框之一为空时,Syncfusion列表框拖放不起作用
- python - Pandas select first x rows corresponding to y values, removing results below x