0Pricing
Jetpack Compose Academy · Aula

Criando um Anel de Progresso em Tempo Real

Combine tela e estado em um componente.

Criando um Anel de Progresso em Tempo Real é uma aula grátis de Jetpack Compose Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Jetpack Compose Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Jetpack Compose Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

The Goal

Time to build something real: a progress ring that fills as a value grows. It blends canvas drawing with live Compose state.

An Arc, Not a Circle

A ring is really an arc. We draw a faint full circle as a track, then a bright arc on top showing the progress so far.

Hold the Progress

Store the value in state so the ring redraws when it changes. A float from 0f to 1f maps cleanly to zero through full.

var progress by remember { mutableStateOf(0.25f) }

Draw the Track

First paint the background ring with drawCircle using a Stroke. A soft gray track shows the full path the progress will fill.

drawCircle(
    color = Color.LightGray,
    style = Stroke(width = 24f)
)

Meet drawArc

The hero is drawArc. It draws a slice of a circle defined by a start angle and a sweep angle, both measured in degrees.

drawArc(
    color = Color.Blue,
    startAngle = -90f,
    sweepAngle = 90f,
    useCenter = false
)

Start at the Top

Angle 0 points right, so we use a startAngle of -90f to begin at the top. That feels natural for a progress indicator.

Sweep by Progress

A full circle is 360 degrees, so the sweepAngle is just progress times 360. At 0.5f the arc covers exactly half the ring.

val sweep = progress * 360f
drawArc(color = Color.Blue, startAngle = -90f, sweepAngle = sweep, useCenter = false)

useCenter Stays False

Keep useCenter false so you draw a ring slice, not a filled pie wedge. With a Stroke style it becomes a clean rounded band.

drawArc(color = Color.Blue, startAngle = -90f, sweepAngle = sweep, useCenter = false, style = Stroke(width = 24f, cap = StrokeCap.Round))

Animate the Value

Wrap the value in animateFloatAsState so changes glide instead of jumping. The ring then smoothly grows toward each new target.

val animated by animateFloatAsState(targetValue = progress)

Add a Gradient

Swap the flat color for a sweepGradient brush and the ring gets a vivid, modern look as the colors rotate around it.

drawArc(brush = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta)), startAngle = -90f, sweepAngle = sweep, useCenter = false, style = Stroke(24f))

Layer the Label

Place a Text showing the percentage in a Box centered over the Canvas. Now your widget reads as a complete, polished control.

Quick Check

How do you turn a 0f-to-1f progress value into the arc's sweep?

Recap

You built a live ring: a track circle, a drawArc swept by progress times 360, animated state, and a gradient stroke. Beautiful work! 🌀

Perguntas Frequentes

A aula “Criando um Anel de Progresso em Tempo Real” é grátis?

Sim — o texto completo de “Criando um Anel de Progresso em Tempo Real” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Jetpack Compose Academy, atualize para CoddyKit PRO. O curso de Jetpack Compose Academy inclui 4 aulas no total.

O que vou aprender em “Criando um Anel de Progresso em Tempo Real”?

Combine tela e estado em um componente. Você pratica Jetpack Compose Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Jetpack Compose Academy?

Nenhuma experiência prévia é necessária. Jetpack Compose Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Criando um Anel de Progresso em Tempo Real”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Jetpack Compose Academy?

Sim. Cada aula de Jetpack Compose Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. DrawScope: Linhas, Retângulos e Círculos
  2. Traçados, Gradientes e Modos de Mesclagem
  3. drawWithCache e Desempenho
  4. Criando um Anel de Progresso em Tempo Real
← Voltar para Jetpack Compose Academy