我试图在视图的底部添加阴影,但我不知道如何在Android上做到这一点。对于elevation,它也在顶部放置了一个阴影。有没有办法像在iOS上那样做呢?
下面是我的代码:
export function makeElevation(elevation) {
const iosShadowElevation = {
shadowOpacity: 0.0015 * elevation + 0.18,
shadowRadius: 0.5 * elevation,
shadowOffset: {
height: 0.6 * elevation,
},
};
const androidShadowElevation = {
elevation,
};
return Platform.OS === 'ios' ? iosShadowElevation : androidShadowElevation;}
左: iOS (预期)
右图: Android
编辑:我找到的唯一“假的”解决方案是使用react-native-linear-gradient来创建自定义阴影。

发布于 2020-08-10 21:17:40
上面的答案非常有帮助,但对我来说效果最好的变通方法是将这两个组件都包装起来,1-放置阴影的组件,2-将阴影放置在上的组件,使用样式规则overflow: "hidden"
示例:
function SomeScreen (){
return (
<View style={{overflow: "hidden"}}/*Top shadow is hidden*/>
<NavBar style={styles.shadow}/*The component dropping a shadow*/ />
<ProductList /*The component under the shadow*/ />
</View>
);
}
const styles = StyleSheet.create({
shadow: {
shadowColor: "black",
shadowOffset: { width: 0, height: 4 },
shadowRadius: 6,
shadowOpacity: 0.2,
elevation: 3,
}
});https://stackoverflow.com/questions/54751815
复制相似问题