Jetpack Compose 中的 X 和 Y 偏移、模糊、不透明度和阴影颜色? [英] X and Y offset, blur, opacity and colour of shadow in Jetpack Compose?
本文介绍了Jetpack Compose 中的 X 和 Y 偏移、模糊、不透明度和阴影颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于 Jetpack Compose 有此限制,我正在寻找变通解决方案对于这个问题?
Since Jetpack Compose has this limitation I'm looking for workaround solution for this problem?
也许 Canvas 可以解决问题?如果有人可以提供如何在 Jetpack Compose 中为 Card
、Box
、Column
、Row<渲染阴影的代码片段,我真的很感激/code> 等使用附加参数,如 X 和 Y 偏移、模糊和不透明度以及自定义实现(画布或其他东西)?
Maybe Canvas could do the trick? I really appreciate if someone can provide code snippets of how to render shadow in Jetpack Compose for Card
, Box
, Column
, Row
etc utilising additional parameters like X and Y offset, blur and opacity with custom implementation (Canvas or something else)?
推荐答案
多亏了这个代码片段
fun Modifier.advancedShadow(
color: Color = Color.Black,
alpha: Float = 0f,
cornersRadius: Dp = 0.dp,
shadowBlurRadius: Dp = 0.dp,
offsetY: Dp = 0.dp,
offsetX: Dp = 0.dp
) = drawBehind {
val shadowColor = color.copy(alpha = alpha).toArgb()
val transparentColor = color.copy(alpha = 0f).toArgb()
drawIntoCanvas {
val paint = Paint()
val frameworkPaint = paint.asFrameworkPaint()
frameworkPaint.color = transparentColor
frameworkPaint.setShadowLayer(
shadowBlurRadius.toPx(),
offsetX.toPx(),
offsetY.toPx(),
shadowColor
)
it.drawRoundRect(
0f,
0f,
this.size.width,
this.size.height,
cornersRadius.toPx(),
cornersRadius.toPx(),
paint
)
}
}
这篇关于Jetpack Compose 中的 X 和 Y 偏移、模糊、不透明度和阴影颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文