Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

ColumnCalculator

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

Utility class that calculates the width 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.

The following is an example of the location and sizes of margins and gutters:

Summary

Public methods

open Int

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

open Int
getColumnSpanWidth(columnSpan: Int)

Returns the width in pixels that the given number of columns will span over.

open Int

Returns the size in pixels of each column.

open Int

Returns the total number of gutters that fit on screen.

open Int

Returns the width of each gutter in pixels.

open static ColumnCalculator!
getInstance(context: Context!)

Gets an instance of the ColumnCalculator.

Public methods

getColumnCount

open fun getColumnCount(): 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.

getColumnSpanWidth

@Px open fun getColumnSpanWidth(columnSpan: Int): Int

Returns the width in pixels that the given number of columns will span over.

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.

getColumnWidth

@Px 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.

getGutterCount

open fun getGutterCount(): 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.

getGutterWidth

@Px open fun getGutterWidth(): Int

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

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

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.