Google is committed to advancing racial equity for Black communities. See how.

ContentScale

@Stable interface ContentScale
androidx.compose.ui.layout.ContentScale

Represents a rule to apply to scale a source rectangle to be inscribed into a destination

Summary

Public methods
abstract ScaleFactor
computeScaleFactor(srcSize: Size, dstSize: Size)

Computes the scale factor to apply to the horizontal and vertical axes independently of one another to fit the source appropriately with the given destination

open Float
scale(srcSize: Size, dstSize: Size)

Computes the scale factor to apply to both dimensions in order to fit the source appropriately with the given destination size

Companion properties
ContentScale

Scale the source uniformly (maintaining the source's aspect ratio) so that both dimensions (width and height) of the source will be equal to or larger than the corresponding dimension of the destination.

ContentScale

Scale horizontal and vertically non-uniformly to fill the destination bounds.

ContentScale

Scale the source maintaining the aspect ratio so that the bounds match the destination height.

ContentScale

Scale the source maintaining the aspect ratio so that the bounds match the destination width.

ContentScale

Scale the source uniformly (maintaining the source's aspect ratio) so that both dimensions (width and height) of the source will be equal to or less than the corresponding dimension of the destination

ContentScale

Scale the source to maintain the aspect ratio to be inside the destination bounds if the source is larger than the destination.

FixedScale

Do not apply any scaling to the source

Public methods

computeScaleFactor

abstract fun computeScaleFactor(
    srcSize: Size,
    dstSize: Size
): ScaleFactor

Computes the scale factor to apply to the horizontal and vertical axes independently of one another to fit the source appropriately with the given destination

scale

open fun scale(
    srcSize: Size,
    dstSize: Size
): Float

Deprecated.

Computes the scale factor to apply to both dimensions in order to fit the source appropriately with the given destination size

Companion properties

Crop

@Stable val Crop: ContentScale

Scale the source uniformly (maintaining the source's aspect ratio) so that both dimensions (width and height) of the source will be equal to or larger than the corresponding dimension of the destination.

This ContentScale implementation in combination with usage of Alignment.Center provides similar behavior to android.widget.ImageView.ScaleType.CENTER_CROP

FillBounds

@Stable val FillBounds: ContentScale

Scale horizontal and vertically non-uniformly to fill the destination bounds.

FillHeight

@Stable val FillHeight: ContentScale

Scale the source maintaining the aspect ratio so that the bounds match the destination height. This can cover a larger area than the destination if the height is larger than the width.

FillWidth

@Stable val FillWidth: ContentScale

Scale the source maintaining the aspect ratio so that the bounds match the destination width. This can cover a larger area than the destination if the width is larger than the height.

Fit

@Stable val Fit: ContentScale

Scale the source uniformly (maintaining the source's aspect ratio) so that both dimensions (width and height) of the source will be equal to or less than the corresponding dimension of the destination

This ContentScale implementation in combination with usage of Alignment.Center provides similar behavior to android.widget.ImageView.ScaleType.FIT_CENTER

Inside

@Stable val Inside: ContentScale

Scale the source to maintain the aspect ratio to be inside the destination bounds if the source is larger than the destination. If the source is smaller than or equal to the destination in both dimensions, this behaves similarly to None. This will always be contained within the bounds of the destination.

This ContentScale implementation in combination with usage of Alignment.Center provides similar behavior to android.widget.ImageView.ScaleType.CENTER_INSIDE

None

@Stable val None: FixedScale

Do not apply any scaling to the source