0Pricing
Jetpack Compose Academy · Lección

Restricciones y medidas intrínsecas

Negocie el tamaño entre el elemento principal y el secundario.

Restricciones y medidas intrínsecas es una lección gratuita de Jetpack Compose Academy en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Jetpack Compose Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Jetpack Compose Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

Constraints Are a Size Contract

A parent passes constraints to each child: the allowed min and max width and height. The child must choose a size that fits inside them. 📏

Four Numbers Define the Box

Every Constraints object holds minWidth, maxWidth, minHeight, and maxHeight. Together they describe the range of sizes a child may pick.

constraints.minWidth
constraints.maxWidth
constraints.maxHeight

Bounded vs Infinite Constraints

A max can be a real number or Infinity. Scrollable parents pass infinite height so children can be as tall as they need.

Loosen Constraints to Allow Smaller

Use copy to relax constraints before measuring. Setting minWidth to zero lets a child be smaller than the parent demands.

val loose = constraints.copy(minWidth = 0, minHeight = 0)

Tighten Constraints to Force a Size

Set min equal to max and you force an exact size. The child has no choice but to be exactly that big.

val fixed = Constraints.fixed(width = 200, height = 100)

Children Negotiate Within Bounds

Layout is a negotiation: the parent offers bounds, the child reports a size, the parent places it. Both sides shape the final result.

Why Intrinsics Exist

Sometimes a parent needs a child's size before the real measure pass. Intrinsic measurements answer that question without committing.

Min and Max Intrinsic Width

Ask minIntrinsicWidth for the smallest width that shows content without clipping, or maxIntrinsicWidth for the natural unwrapped width.

measurable.maxIntrinsicWidth(height)

A Classic Use: Equal Heights

The built-in IntrinsicSize.Min modifier uses intrinsics to make a Row's children share the tallest height, like a divider matching its neighbors.

Row(Modifier.height(IntrinsicSize.Min)) { }

Intrinsics Cost an Extra Query

Intrinsic queries run extra work, so use them only when needed. Most custom layouts get by with constraints alone. ⚡

Constraints Flow Down the Tree

Constraints cascade from the root down through every parent. Mastering how to tighten and loosen them is the heart of custom layout work.

Quick Check

How do you force a child to be an exact, fixed size?

Recap: Constraints & Intrinsics

Constraints set a child's allowed size range; loosen or tighten them with copy. Intrinsics peek at a size early, but cost extra and are used sparingly. ✅

Preguntas frecuentes

¿La lección «Restricciones y medidas intrínsecas» es gratis?

Sí — el texto completo de «Restricciones y medidas intrínsecas» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Jetpack Compose Academy, actualiza a CoddyKit PRO. El curso de Jetpack Compose Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Restricciones y medidas intrínsecas»?

Negocie el tamaño entre el elemento principal y el secundario. Practicas Jetpack Compose Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Jetpack Compose Academy?

No se requiere experiencia previa. Jetpack Compose Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.

¿Cuánto tiempo toma la lección «Restricciones y medidas intrínsecas»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Jetpack Compose Academy?

Sí. Cada lección de Jetpack Compose Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. El modelo de medir y colocar
  2. Escribir un Composable Layout
  3. Restricciones y medidas intrínsecas
  4. Un FlowRow que ajusta los chips
← Volver a Jetpack Compose Academy