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

Density

interface Density
androidx.ui.unit.Density

A density of the screen. Used for the conversions between Dp, Px, IntPx and TextUnit.


//Unresolved: androidx.ui.unit.samples.WithDensitySample

Summary

Public methods

open Dp

Convert Sp to Dp.

open Dp

Convert Px to Dp.

open Dp

Convert IntPx to Dp.

open Dp

Convert a Float pixel value to a Dp

open Dp

Convert a Int pixel value to a Dp

open IntPx

Convert Dp to IntPx by rounding

open IntPx

Convert Sp to IntPx by rounding

open Px

Convert Dp to Px.

open Px

Convert Sp to Px.

open PxSize

Convert a Size to a PxSize.

open Rect

Convert a Bounds to a Rect.

open TextUnit

Convert Dp to Sp.

open TextUnit

Convert Px to Sp.

open TextUnit

Convert IntPx to Sp.

open TextUnit

Convert a Float pixel value to a Sp

open TextUnit

Convert a Int pixel value to a Sp

Extension functions

From androidx.ui.layout
Constraints

Creates the Constraints corresponding to the current DpConstraints.

DpConstraints

Creates the DpConstraints corresponding to the current Constraints.

Properties

abstract Float

The logical density of the display.

abstract Float

Current user preference for the scaling factor for fonts.

Public methods

toDp

open fun TextUnit.toDp(): Dp

Convert Sp to Dp.

Exceptions
IllegalStateException if TextUnit other than SP unit is specified.

toDp

open fun Px.toDp(): Dp

Convert Px to Dp.

toDp

open fun IntPx.toDp(): Dp

Convert IntPx to Dp.

toDp

open fun Float.toDp(): Dp

Convert a Float pixel value to a Dp

toDp

open fun Int.toDp(): Dp

Convert a Int pixel value to a Dp

toIntPx

open fun Dp.toIntPx(): IntPx

Convert Dp to IntPx by rounding

toIntPx

open fun TextUnit.toIntPx(): IntPx

Convert Sp to IntPx by rounding

toPx

open fun Dp.toPx(): Px

Convert Dp to Px. Pixels are used to paint to Canvas.

toPx

open fun TextUnit.toPx(): Px

Convert Sp to Px. Pixels are used to paint to Canvas.

Exceptions
IllegalStateException if TextUnit other than SP unit is specified.

toPx

open fun Size.toPx(): PxSize

Convert a Size to a PxSize.

toRect

open fun Bounds.toRect(): Rect

Convert a Bounds to a Rect.

toSp

open fun Dp.toSp(): TextUnit

Convert Dp to Sp. Sp is used for font size, etc.

toSp

open fun Px.toSp(): TextUnit

Convert Px to Sp.

toSp

open fun IntPx.toSp(): TextUnit

Convert IntPx to Sp.

toSp

open fun Float.toSp(): TextUnit

Convert a Float pixel value to a Sp

toSp

open fun Int.toSp(): TextUnit

Convert a Int pixel value to a Sp

Properties

density

abstract val density: Float

The logical density of the display. This is a scaling factor for the Dp unit.

fontScale

abstract val fontScale: Float

Current user preference for the scaling factor for fonts.