Dp
@Immutable inline class Dp : Comparable<Dp>
kotlin.Any | |
↳ | androidx.compose.ui.unit.Dp |
Dimension value representing device-independent pixels (dp). Component APIs specify their dimensions such as line thickness in DP with Dp objects. Hairline (1 pixel) thickness may be specified with Hairline, a dimension that take up no space. Dp are normally defined using dp, which can be applied to Int, Double, and Float. val leftMargin = 10.dp val rightMargin = 10f.dp val topMargin = 20.0.dp val bottomMargin = 10.dp Drawing is done in pixels. To retrieve the pixel size of a Dp, use toPx: val lineThicknessPx = lineThickness.toPx(context) toPx is normally needed only for painting operations.
Summary
Public constructors | |
---|---|
Dimension value representing device-independent pixels (dp). |
Public methods | |
---|---|
operator Int |
Support comparing Dimensions with comparison operators. |
operator Dp |
Divide a Dp by a scalar. |
operator Dp | |
operator Float |
Divide by another Dp to get a scalar. |
operator Dp |
Subtract a Dp from another one. |
operator Dp |
Add two Dps together. |
operator Dp |
Multiply a Dp by a scalar. |
operator Dp | |
String |
toString() |
operator Dp |
This is the same as multiplying the Dp by -1. |
Extension functions | ||||||||
---|---|---|---|---|---|---|---|---|
From androidx.compose.ui.test
|
||||||||
From androidx.compose.ui.unit
|
Inherited extension functions | ||
---|---|---|
From androidx.core.util
|
Properties | |
---|---|
Float |
Companion properties | |
---|---|
Dp |
A dimension used to represent a hairline drawing element. |
Dp |
Infinite dp dimension. |
Dp |
Constant that means unspecified Dp |
Extension properties | ||||||
---|---|---|---|---|---|---|
From androidx.compose.ui.unit
|
Public constructors
<init>
Dp(value: Float)
Dimension value representing device-independent pixels (dp). Component APIs specify their dimensions such as line thickness in DP with Dp objects. Hairline (1 pixel) thickness may be specified with Hairline, a dimension that take up no space. Dp are normally defined using dp, which can be applied to Int, Double, and Float. val leftMargin = 10.dp val rightMargin = 10f.dp val topMargin = 20.0.dp val bottomMargin = 10.dp Drawing is done in pixels. To retrieve the pixel size of a Dp, use toPx: val lineThicknessPx = lineThickness.toPx(context) toPx is normally needed only for painting operations.
Public methods
compareTo
@Stable operator fun compareTo(other: Dp): Int
Support comparing Dimensions with comparison operators.
toString
@Stable fun toString(): String
unaryMinus
@Stable inline operator fun unaryMinus(): Dp
This is the same as multiplying the Dp by -1.0.
Properties
value
val value: Float
Companion properties
Hairline
@Stable val Hairline: Dp
A dimension used to represent a hairline drawing element. Hairline elements take up no space, but will draw a single pixel, independent of the device's resolution and density.