css - 从中心开始渐变 - 反应原生中的 LinearGradient
问题描述
我需要在我的 react native 应用程序中的一个按钮上应用一个盒子阴影,但 android 不支持盒子阴影属性。所以我试图创建一个阴影视图LinearGradient
并将按钮放在该视图的中心。像这样的东西
<LinearGradient
colors={['transparent', backgroundColor]}
start={{ x: 0.5, y: 0.5 }}
end={{ x: 1, y: 1 }}
style={{
width: '100%',
padding: 5,
height: 60,
justifyContent: 'center',
alignItems: 'flex-start',
marginTop: 0,
borderRadius: 2,
backgroundColor: 'transparent',
zIndex: 2,
bottom: 0,
}}>
<Pressable
onPress={onPress}
disabled={disabled}
style={({ pressed }) => [
{
borderWidth: state === 'primary_link' ? 0 : pressed ? 4 : borderWidth,
},
styles.background,
]}>
<ButtonTitle />
</Pressable>
</LinearGradient>
我尝试更改开始值和结束值,但无法从中心开始。有没有办法使用 LinearGradient 做到这一点?我试图得到这样的东西
解决方案
顾名思义,LinearGradient 仅用于线性渐变。您描述的是径向渐变。看到这个问题:https ://github.com/react-native-linear-gradient/react-native-linear-gradient/issues/29
您可能有如下所述的框阴影:Creating a UI with box shadow in react native
boxWithShadow: {
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 5
}
推荐阅读
- javascript - "(" 意外的 Python 调用 javascript
- amazon-web-services - 启动配置中给出的用户数据不起作用
- python - 如何在 PHP 中启动文件?
- python - 如何在 Python 中定义一个等于多项式的函数
- python - Python PIL:旋转和缩放图像,使两个点匹配另外两个点
- recursion - 为什么我的迭代高阶过程比等效的递归过程给出更精确的结果?
- c# - 链接的键盘键与它们链接的表单按钮的行为不同
- bash - 读取:在 bash 中读取输入时不是有效的标识符
- java - FXML 文件中的加载异常错误阻止程序运行
- windows - imagemagick 批处理命令后的错误级别 0