我正在零食博览会上试用你的代码,它使用最新的react原生版本(55.4)。将高程应用于图像属性时没有警告,它只是工作正常,图像也在卡的上方。如果您的react原生版本发出警告,只需将其包装在视图中,并对该视图应用高程。此外,请记住zIndex会受到视图高度的影响(仅限Android)。由于已将标高:4应用于卡盒,因此必须给出标高>=4.对于图像组件,否则将在卡盒下方绘制。
零食示例:
https://snack.expo.io/B14UPA9Bm
也可以通过更改组件的顺序来避免Zindex,
// Render the image component after your card box this way you can avoid setting the zIndex
<View style={styles.cardContainer}>
<View style={styles.cardBox}>
<View style={styles.container}>
<Text style={styles.txtTitle}>
My title
</Text>
</View>
</View>
<Image source={iconPlayers} style={styles.iconTop} />
</View>
cardBox: {
borderRadius: 20,
backgroundColor: "#FFF",
padding: 5,
marginBottom: 10,
borderColor: "#DDD",
elevation: 4,
paddingTop: 40,
},
cardContainer: {
marginTop: 40,
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
txtTitle: {
color: "#000",
textAlign: "center",
fontWeight: "bold",
},
iconTop: {
width: 60,
height: 60,
//zIndex: 999, not required now
position: "absolute",
top: -30,
elevation: 4,
alignSelf: "center",
},
检查并告知它是否在Android和iOS中工作。谢谢