The second Android 11 Developer Preview is now available, test it out and share your feedback.

LayoutAspectRatio

data class LayoutAspectRatio : LayoutModifier
kotlin.Any
   ↳ androidx.ui.layout.LayoutAspectRatio

A layout modifier that attempts to size a layout to match a specified aspect ratio. The layout modifier will try to match one of the incoming constraints, in the following order: maxWidth, maxHeight, minWidth, minHeight. The size in the other dimension will then be computed according to the aspect ratio. Note that the provided aspectRatio will always correspond to the width/height ratio.

If a valid size that satisfies the constraints is found this way, the modifier will size the target layout to it: the layout will be measured with the tight constraints to match the size. If a child is present, it will be measured with tight constraints to match the size. If no valid size is found, the aspect ratio will not be satisfied, and the target layout will be measured with the original constraints.

Example usage:

import androidx.ui.foundation.Box
import androidx.ui.layout.LayoutAspectRatio
import androidx.ui.layout.LayoutWidth

Box(LayoutWidth(100.dp) + LayoutAspectRatio(2f), backgroundColor = Color.Green)

Summary

Public constructors

<init>(aspectRatio: Float)

A layout modifier that attempts to size a layout to match a specified aspect ratio.

Public methods

IntPx
Density.maxIntrinsicHeightOf(measurable: Measurable, width: IntPx, layoutDirection: LayoutDirection)

Determines the modified maximum intrinsic height of measurable.

IntPx
Density.maxIntrinsicWidthOf(measurable: Measurable, height: IntPx, layoutDirection: LayoutDirection)

Determines the modified maximum intrinsic width of measurable.

IntPx
Density.minIntrinsicHeightOf(measurable: Measurable, width: IntPx, layoutDirection: LayoutDirection)

Determines the modified minimum intrinsic height of measurable.

IntPx
Density.minIntrinsicWidthOf(measurable: Measurable, height: IntPx, layoutDirection: LayoutDirection)

Determines the modified minimum intrinsic width of measurable.

Constraints
Density.modifyConstraints(constraints: Constraints, layoutDirection: LayoutDirection)

Modifies constraints for performing measurement of the modified layout element.

Inherited functions

Properties

Float

A positive non-zero value representing the aspect ratio.

Public constructors

<init>

LayoutAspectRatio(aspectRatio: Float)

A layout modifier that attempts to size a layout to match a specified aspect ratio. The layout modifier will try to match one of the incoming constraints, in the following order: maxWidth, maxHeight, minWidth, minHeight. The size in the other dimension will then be computed according to the aspect ratio. Note that the provided aspectRatio will always correspond to the width/height ratio.

If a valid size that satisfies the constraints is found this way, the modifier will size the target layout to it: the layout will be measured with the tight constraints to match the size. If a child is present, it will be measured with tight constraints to match the size. If no valid size is found, the aspect ratio will not be satisfied, and the target layout will be measured with the original constraints.

Example usage:

import androidx.ui.foundation.Box
import androidx.ui.layout.LayoutAspectRatio
import androidx.ui.layout.LayoutWidth

Box(LayoutWidth(100.dp) + LayoutAspectRatio(2f), backgroundColor = Color.Green)
Parameters
aspectRatio: Float A positive non-zero value representing the aspect ratio.

Public methods

maxIntrinsicHeightOf

fun Density.maxIntrinsicHeightOf(
    measurable: Measurable,
    width: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Determines the modified maximum intrinsic height of measurable. See Measurable.maxIntrinsicHeight.

maxIntrinsicWidthOf

fun Density.maxIntrinsicWidthOf(
    measurable: Measurable,
    height: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Determines the modified maximum intrinsic width of measurable. See Measurable.maxIntrinsicWidth.

minIntrinsicHeightOf

fun Density.minIntrinsicHeightOf(
    measurable: Measurable,
    width: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Determines the modified minimum intrinsic height of measurable. See Measurable.minIntrinsicHeight.

minIntrinsicWidthOf

fun Density.minIntrinsicWidthOf(
    measurable: Measurable,
    height: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Determines the modified minimum intrinsic width of measurable. See Measurable.minIntrinsicWidth.

modifyConstraints

fun Density.modifyConstraints(
    constraints: Constraints,
    layoutDirection: LayoutDirection
): Constraints

Modifies constraints for performing measurement of the modified layout element.

Properties

aspectRatio

val aspectRatio: Float

A positive non-zero value representing the aspect ratio.