belongs to Maven artifact androidx.car:car:1.0.0-alpha1

ColumnCalculator

public class ColumnCalculator
extends Object

java.lang.Object
   ↳ 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

int getColumnWidth()

Returns the size in pixels of each column.

int getGutterSize()

Returns the size of each gutter in pixels.

static ColumnCalculator getInstance(Context context)

Gets an instance of the ColumnCalculator.

int getNumOfColumns()

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

int getNumOfGutters()

Returns the total number of gutters that fit on screen.

int getSizeForColumnSpan(int columnSpan)

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

Inherited methods

Public methods

getColumnWidth

int getColumnWidth ()

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.

Returns
int The width of a single column in pixels.

getGutterSize

int getGutterSize ()

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

Returns
int The size of a single gutter in pixels.

getInstance

ColumnCalculator getInstance (Context context)

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.

Returns
ColumnCalculator An instance of ColumnCalculator.

getNumOfColumns

int getNumOfColumns ()

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

Returns
int The total number of columns that fit on the screen.

getNumOfGutters

int getNumOfGutters ()

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.

Returns
int The number of gutters on screen.

getSizeForColumnSpan

int getSizeForColumnSpan (int columnSpan)

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.

Parameters
columnSpan int

Returns
int The size in pixels for a given column span.