compose 进度环

@Composable
fun InfiniteLoadingSpinner(
    modifier: Modifier = Modifier,
    primaryColor: Color = MaterialTheme.colorScheme.primary,
    backgroundColor: Color = primaryColor.copy(alpha = 0.2f),
    sweepAngle: Float = 90f,
    size: Dp = 350.dp,
    strokeWidth: Dp = 45.dp
) {
    val infiniteTransition = rememberInfiniteTransition()

    val rotation by infiniteTransition.animateFloat(
        initialValue = 0f,
        targetValue = 360f,
        animationSpec = infiniteRepeatable(
            animation = tween(durationMillis = 1200, easing = LinearEasing)
        )
    )

    Box(
        modifier = modifier
            .size(size)
            .aspectRatio(1f)
    ) {
        Canvas(modifier = Modifier.fillMaxSize()) {
            val halfStroke = strokeWidth.toPx() / 2
            val rect = Rect(
                left = halfStroke,
                top = halfStroke,
                right = size.toPx() - halfStroke,
                bottom = size.toPx() - halfStroke
            )

            // 绘制背景环
            drawCircle(
                color = backgroundColor,
                radius = size.toPx() / 2 - halfStroke,
                style = Stroke(strokeWidth.toPx())
            )

            // 绘制主色进度弧
            drawArc(
                color = primaryColor,
                startAngle = rotation - 90,
                sweepAngle = sweepAngle.coerceIn(0f, 360f),
                useCenter = false,
                style = Stroke(width = strokeWidth.toPx(), cap = StrokeCap.Round),
                topLeft = Offset(rect.left, rect.top),
                size = Size(rect.width, rect.height)
            )
        }
    }
}

使用

 InfiniteLoadingSpinner(
                    primaryColor = Color_Primary_Red,
                    backgroundColor = Color_000000_10,
                    sweepAngle = 45f, // 主色弧占120度
                    size = 350.dp,
                    strokeWidth = 45.dp
                )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值