public interface ContentScale
Represents a rule to apply to scale a source rectangle to be inscribed into a destination
Functions
computeScaleFactor
public 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
Members
Companion
public companion object
Companion object containing commonly used ContentScale implementations
Properties
Crop
public val Crop: ContentScale =
object : ContentScale {
override fun computeScaleFactor(srcSize: Size, dstSize: Size): ScaleFactor =
computeFillMaxDimension(srcSize, dstSize).let { ScaleFactor(it, it) }
}
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 androidx.compose.ui.Alignment.Center provides similar behavior to android.widget.ImageView.ScaleType.CENTER_CROP
Fit
public val Fit: ContentScale =
object : ContentScale {
override fun computeScaleFactor(srcSize: Size, dstSize: Size): ScaleFactor =
computeFillMinDimension(srcSize, dstSize).let { ScaleFactor(it, it) }
}
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 androidx.compose.ui.Alignment.Center provides similar behavior to android.widget.ImageView.ScaleType.FIT_CENTER
FillHeight
public val FillHeight: ContentScale =
object : ContentScale {
override fun computeScaleFactor(srcSize: Size, dstSize: Size): ScaleFactor =
computeFillHeight(srcSize, dstSize).let { ScaleFactor(it, it) }
}
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
public val FillWidth: ContentScale =
object : ContentScale {
override fun computeScaleFactor(srcSize: Size, dstSize: Size): ScaleFactor =
computeFillWidth(srcSize, dstSize).let { ScaleFactor(it, it) }
}
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.
Inside
public val Inside: ContentScale =
object : ContentScale {
override fun computeScaleFactor(srcSize: Size, dstSize: Size): ScaleFactor {
return if (srcSize.width <= dstSize.width && srcSize.height <= dstSize.height) {
ScaleFactor(1.0f, 1.0f)
} else {
computeFillMinDimension(srcSize, dstSize).let { ScaleFactor(it, it) }
}
}
}
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 androidx.compose.ui.Alignment.Center provides similar behavior to android.widget.ImageView.ScaleType.CENTER_INSIDE
None
@Stable public val None: FixedScale = FixedScale(1.0f)
Do not apply any scaling to the source
FillBounds
public val FillBounds: ContentScale =
object : ContentScale {
override fun computeScaleFactor(srcSize: Size, dstSize: Size): ScaleFactor =
ScaleFactor(
computeFillWidth(srcSize, dstSize),
computeFillHeight(srcSize, dstSize),
)
}
Scale horizontal and vertically non-uniformly to fill the destination bounds.