ColumnCalculator

open class ColumnCalculator
kotlin.Any
   ↳ androidx.car.utils.ColumnCalculator

Utility class that calculates the size of the columns that will fit on the screen. A column's width is determined by the size of the margins and gutters (space between the columns) that fit on-screen.

Refer to the appropriate dimens and integers for the size of the margins and number of columns.

Summary

Public methods
open Int

Returns the total number of gutters that fit on screen.

open Int

Returns the total number of columns that fit on the current screen.

open Int

Returns the size of each gutter in pixels.

open Int

Returns the size in pixels of each column.

open Int

Returns the size in pixels for the given number of columns.

open static ColumnCalculator!
getInstance(context: Context!)

Gets an instance of the ColumnCalculator.

Public methods

getNumOfGutters

open fun getNumOfGutters(): Int

Returns the total number of gutters that fit on screen. A gutter is the space between each column. This value is always one less than the number of columns.

Return
Int: The number of gutters on screen.

getNumOfColumns

open fun getNumOfColumns(): Int

Returns the total number of columns that fit on the current screen.

Return
Int: The total number of columns that fit on the screen.

getGutterSize

open fun getGutterSize(): Int

Returns the size of each gutter in pixels. A gutter is the space between each column.

Return
Int: The size of a single gutter in pixels.

getColumnWidth

open fun getColumnWidth(): Int

Returns the size in pixels of each column. The column width is determined by the size of the screen divided by the number of columns, size of gutters and margins.

Return
Int: The width of a single column in pixels.

getSizeForColumnSpan

open fun getSizeForColumnSpan(columnSpan: Int): Int

Returns the size in pixels for the given number of columns. This value takes into account the size of the gutter between the columns as well. For example, for a column span of four, the size returned is the sum of four columns and three gutters.

Return
Int: The size in pixels for a given column span.

getInstance

open static fun getInstance(context: Context!): ColumnCalculator!

Gets an instance of the ColumnCalculator. If this is the first time that this method has been called, then the given Context will be used to retrieve resources.

Parameters
context Context!: The current calling Context.
Return
ColumnCalculator!: An instance of ColumnCalculator.