Jetpack Compose Academy · Aula

weight e Dimensionamento Flexível

Distribua o espaço proporcionalmente em linhas e colunas.

Aula 4 de 413 etapas

weight e Dimensionamento Flexível é 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.

Flexible Space

Sometimes you want children to share space, not take fixed sizes. The weight modifier divides leftover room proportionally. ⚖️

Where weight Lives

weight works only inside a Row or Column. It is part of the layout scope those containers provide to their children.

Equal Split

Give two children the same weight and they share the space evenly, each taking half of what is available.

Box(Modifier.weight(1f))
Box(Modifier.weight(1f))

Uneven Split

Weights are ratios. A child with weight(2f) gets twice the space of a sibling with weight(1f).

Box(Modifier.weight(2f))
Box(Modifier.weight(1f))

Fixed Plus Flexible

Mix and match: give one child a fixed size and let another use weight to absorb whatever space remains.

Box(Modifier.width(80.dp))
Box(Modifier.weight(1f))

Push to the Edge

A single weight on a spacer acts like a push, sending the next child all the way to the far end of the row.

Text("Left")
Spacer(Modifier.weight(1f))
Text("Right")

Weights Run First

Compose measures fixed children first, then splits the leftover space among weighted ones. That is why weight needs siblings to push against.

The fill Flag

By default a weighted child fills its share. Pass fill = false to let it stay smaller than the space it was given.

Modifier.weight(1f, fill = false)

Weighted Columns

The same idea works vertically. In a Column, weight divides the leftover height instead of width.

Column {
  Box(Modifier.weight(1f))
  Box(Modifier.weight(1f))
}

Responsive by Design

Because weights are ratios, your layout scales gracefully across phone and tablet widths without hardcoded numbers.

A Common Pattern

Label on the left, value filling the rest: a weighted row is the classic recipe for clean settings and list rows.

Row {
  Text("Name")
  Text("Sam", Modifier.weight(1f))
}

Quick Check

Two children sit in a Row with weight(3f) and weight(1f). How is the space shared?

Recap

You can now share space flexibly. weight splits leftover room by ratio inside Rows and Columns for responsive layouts. 🎯

Grátis para começar

Aprenda Kotlin com um tutor de IA — grátis

Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.

Cursos
30
Aulas
120

Perguntas Frequentes

A aula “weight e Dimensionamento Flexível” é grátis?

Sim — o texto completo de “weight e Dimensionamento Flexível” é 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 “weight e Dimensionamento Flexível”?

Distribua o espaço proporcionalmente em linhas e colunas. 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 “weight e Dimensionamento Flexível”?

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. Preenchimento, Tamanho e fillMaxWidth
  2. Plano de Fundo, Borda e Recorte
  3. Por que a Ordem dos Modificadores Importa
  4. weight e Dimensionamento Flexível
← Voltar para Jetpack Compose Academy