{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

Size

value public final class Size


Holds a 2D floating-point size.

You can think of this as an Offset from the origin.

Summary

Nested types

public static class Size.Companion

Public methods

final float
final float
final @NonNull Size
copy(float width, float height)

Returns a copy of this Size instance optionally overriding the width or height parameter

final @NonNull Size
div(float operand)

Division operator.

final float
final float

The greater of the magnitudes of the width and the height.

final float

The lesser of the magnitudes of the width and the height.

final float
final boolean

Whether this size encloses a non-zero area.

final @NonNull Size
times(float operand)

Multiplication operator.

@NonNull String

Extension functions

final @NonNull Size
ScaleFactorKt.div(
    @NonNull Size receiver,
    @NonNull ScaleFactor scaleFactor
)

Division operator with Size

final @NonNull Size
ScaleFactorKt.times(
    @NonNull Size receiver,
    @NonNull ScaleFactor scaleFactor
)

Multiplication operator with Size.

final @NonNull Offset

Returns the Offset of the center of the rect from the point of 0, 0 with this Size.

final boolean

false when this is Size.Unspecified.

final boolean

true when this is Size.Unspecified.

final @NonNull Size
SizeKt.takeOrElse(
    @NonNull Size receiver,
    @NonNull Function0<@NonNull Size> block
)

If this Size isSpecified then this is returned, otherwise block is executed and its result is returned.

final @NonNull Rect

Convert a Size to a Rect.

Public methods

component1

public final float component1()

component2

public final float component2()

copy

public final @NonNull Size copy(float width, float height)

Returns a copy of this Size instance optionally overriding the width or height parameter

div

public final @NonNull Size div(float operand)

Division operator.

Returns a Size whose dimensions are the dimensions of the left-hand-side operand (a Size) divided by the scalar right-hand-side operand (a Float).

getHeight

public final float getHeight()

getMaxDimension

public final float getMaxDimension()

The greater of the magnitudes of the width and the height.

getMinDimension

public final float getMinDimension()

The lesser of the magnitudes of the width and the height.

getWidth

public final float getWidth()

isEmpty

public final boolean isEmpty()

Whether this size encloses a non-zero area.

Negative areas are considered empty.

times

public final @NonNull Size times(float operand)

Multiplication operator.

Returns a Size whose dimensions are the dimensions of the left-hand-side operand (a Size) multiplied by the scalar right-hand-side operand (a Float).

toString

public @NonNull String toString()

Extension functions

ScaleFactorKt.div

public final @NonNull Size ScaleFactorKt.div(
    @NonNull Size receiver,
    @NonNull ScaleFactor scaleFactor
)

Division operator with Size

Return a new Size with the width and height divided by ScaleFactor.scaleX and ScaleFactor.scaleY respectively

ScaleFactorKt.times

public final @NonNull Size ScaleFactorKt.times(
    @NonNull Size receiver,
    @NonNull ScaleFactor scaleFactor
)

Multiplication operator with Size.

Return a new Size with the width and height multiplied by the ScaleFactor.scaleX and ScaleFactor.scaleY respectively

SizeKt.getCenter

public final @NonNull Offset SizeKt.getCenter(@NonNull Size receiver)

Returns the Offset of the center of the rect from the point of 0, 0 with this Size.

SizeKt.isSpecified

public final boolean SizeKt.isSpecified(@NonNull Size receiver)

false when this is Size.Unspecified.

SizeKt.isUnspecified

public final boolean SizeKt.isUnspecified(@NonNull Size receiver)

true when this is Size.Unspecified.

SizeKt.takeOrElse

public final @NonNull Size SizeKt.takeOrElse(
    @NonNull Size receiver,
    @NonNull Function0<@NonNull Size> block
)

If this Size isSpecified then this is returned, otherwise block is executed and its result is returned.

SizeKt.toRect

public final @NonNull Rect SizeKt.toRect(@NonNull Size receiver)

Convert a Size to a Rect.