我想在 Android Jetpack Compose 中创建这样的角度渐变。
渐变是在 Figma 中制作的,下面是 Figma Inspect 中的 android 代码。
我只能找到只有一个角度的线性渐变的资源。
如何在 Jetpack compose 中创建这个角度渐变?
初始状态看起来像这样 ( animatedOffset = 0f)
我想得到1f反向梯度:
当前代码:
val transition = rememberInfiniteTransition(label = "NavIconGradientAnim")
val animatedOffset by transition.animateFloat(
initialValue = 0f, targetValue = 1f,
label = "NavIconGradientAnimOffset",
animationSpec = infiniteRepeatable(
animation = tween(1500, easing = LinearEasing),
repeatMode = RepeatMode.Reverse
)
)
Image(
painterResource(id = item.icon),
contentDescription = null,
modifier = Modifier.drawWithCache {
onDrawWithContent {
with(drawContext.canvas.nativeCanvas) {
val angle = 45f
val endX = drawContext.size.width
val endY = (endX * kotlin.math.tan(Math.toRadians(angle.toDouble()))).toFloat()
val checkPoint = saveLayer(null, null)
drawContent()
val gradient …Run Code Online (Sandbox Code Playgroud) android android-animation android-jetpack-compose jetpack-compose-animation android-jetpack-compose-animation