getDimensionPixelSize

open fun getDimensionPixelSize(@NonNull context: Context, @NonNull attributes: TypedArray, @StyleableRes index: Int, defaultValue: Int): Int

Retrieve a dimensional unit attribute at index for use as a size in raw pixels. A size conversion involves rounding the base value, and ensuring that a non-zero base value is at least one pixel in size.

This method will throw an exception if the attribute is defined but is not a dimension.

Return

Attribute dimension value multiplied by the appropriate metric and truncated to integer pixels, or defaultValue if not defined.

Parameters

context

The Context the view is running in, through which the current theme, resources, etc can be accessed.

attributes

array of typed attributes from which the dimension unit must be read.

index

Index of attribute to retrieve.

defaultValue

Value to return if the attribute is not defined or not a resource.

See also

Throws

if the attribute is defined but is not a dimension.