GridLayout

public class GridLayout extends ViewGroup


A layout that places its children in a rectangular grid.

The grid is composed of a set of infinitely thin lines that separate the viewing area into cells. Throughout the API, grid lines are referenced by grid indices. A grid with N columns has N + 1 grid indices that run from 0 through N inclusive. Regardless of how GridLayout is configured, grid index 0 is fixed to the leading edge of the container and grid index N is fixed to its trailing edge (after padding is taken into account).

Row and Column Specs Children occupy one or more contiguous cells, as defined by their rowSpec and columnSpec layout parameters. Each spec defines the set of rows or columns that are to be occupied; and how children should be aligned within the resulting group of cells. Although cells do not normally overlap in a GridLayout, GridLayout does not prevent children being defined to occupy the same cell or group of cells. In this case however, there is no guarantee that children will not themselves overlap after the layout operation completes. Default Cell Assignment If a child does not specify the row and column indices of the cell it wishes to occupy, GridLayout assigns cell locations automatically using its: orientation, rowCount and columnCount properties. Space Space between children may be specified either by using instances of the dedicated android.widget.Space view or by setting the leftMargin, topMargin, rightMargin and bottomMargin layout parameters. When the useDefaultMargins property is set, default margins around children are automatically allocated based on the prevailing UI style guide for the platform. Each of the margins so defined may be independently overridden by an assignment to the appropriate layout parameter. Default values will generally produce a reasonable spacing between components but values may change between different releases of the platform. Excess Space Distribution GridLayout's distribution of excess space accommodates the principle of weight. In the event that no weights are specified, columns and rows are taken as flexible if their views specify some form of alignment within their groups.

The flexibility of a view is therefore influenced by its alignment which is, in turn, typically defined by setting the gravity property of the child's layout parameters. If either a weight or alignment were defined along a given axis then the component is taken as flexible in that direction. If no weight or alignment was set, the component is instead assumed to be inflexible.

Multiple components in the same row or column group are considered to act in parallel. Such a group is flexible only if all of the components within it are flexible. Row and column groups that sit either side of a common boundary are instead considered to act in series. The composite group made of these two elements is flexible if one of its elements is flexible.

To make a column stretch, make sure all of the components inside it define a weight or a gravity. To prevent a column from stretching, ensure that one of the components in the column does not define a weight or a gravity.

When the principle of flexibility does not provide complete disambiguation, GridLayout's algorithms favour rows and columns that are closer to its right and bottom edges. To be more precise, GridLayout treats each of its layout parameters as a constraint in the a set of variables that define the grid-lines along a given axis. During layout, GridLayout solves the constraints so as to return the unique solution to those constraints for which all variables are less-than-or-equal-to the corresponding value in any other valid solution.

Interpretation of GONE For layout purposes, GridLayout treats views whose visibility status is GONE, as having zero width and height. This is subtly different from the policy of ignoring views that are marked as GONE outright. If, for example, a gone-marked view was alone in a column, that column would itself collapse to zero width if and only if no gravity was defined on the view. If gravity was defined, then the gone-marked view has no effect on the layout and the container should be laid out as if the view had never been added to it. GONE views are taken to have zero weight during excess space distribution.

These statements apply equally to rows as well as columns, and to groups of rows or columns.

See GridLayout.LayoutParams for a full description of the layout parameters used by GridLayout.

name android:orientation

name android:rowCount

name android:columnCount

name android:useDefaultMargins

name android:rowOrderPreserved

name android:columnOrderPreserved

Summary

Nested types

public abstract class GridLayout.Alignment

Alignments specify where a view should be placed within a cell group and what size it should be.

Layout information associated with each of the children of a GridLayout.

public class GridLayout.Spec

A Spec defines the horizontal or vertical characteristics of a group of cells.

Constants

static final int

This constant is an alignmentMode.

static final int

This constant is an alignmentMode.

static final GridLayout.Alignment

Indicates that a view should be aligned with the baselines of the other views in its cell group.

static final GridLayout.Alignment

Indicates that a view should be aligned with the bottom edges of the other views in its cell group.

static final GridLayout.Alignment

Indicates that a view should be centered with the other views in its cell group.

static final GridLayout.Alignment

Indicates that a view should be aligned with the end edges of the other views in its cell group.

static final GridLayout.Alignment

Indicates that a view should expanded to fit the boundaries of its cell group.

static final int

The horizontal orientation.

static final GridLayout.Alignment

Indicates that a view should be aligned with the left edges of the other views in its cell group.

static final GridLayout.Alignment

Indicates that a view should be aligned with the right edges of the other views in its cell group.

static final GridLayout.Alignment

Indicates that a view should be aligned with the start edges of the other views in its cell group.

static final GridLayout.Alignment

Indicates that a view should be aligned with the top edges of the other views in its cell group.

static final int
UNDEFINED = -2147483648

The constant used to indicate that a value is undefined.

static final int

The vertical orientation.

Public constructors

GridLayout(Context context, AttributeSet attrs)
GridLayout(Context context, AttributeSet attrs, int defStyle)

Public methods

GridLayout.LayoutParams
int

Returns the alignment mode.

int

Returns the current number of columns.

int

Returns the current orientation.

Printer

Return the printer that will log diagnostics from this layout.

int

Returns the current number of rows.

boolean

Returns whether or not this GridLayout will allocate default margins when no corresponding layout parameters are defined.

boolean

Returns whether or not column boundaries are ordered by their grid indices.

boolean

Returns whether or not row boundaries are ordered by their grid indices.

void
void
setAlignmentMode(int alignmentMode)

Sets the alignment mode to be used for all of the alignments between the children of this container.

void
setColumnCount(int columnCount)

ColumnCount is used only to generate default column/column indices when they are not specified by a component's layout parameters.

void
setColumnOrderPreserved(boolean columnOrderPreserved)

When this property is true, GridLayout is forced to place the column boundaries so that their associated grid indices are in ascending order in the view.

void
setOrientation(int orientation)

GridLayout uses the orientation property for two purposes:

void

Set the printer that will log diagnostics from this layout.

void
setRowCount(int rowCount)

RowCount is used only to generate default row/column indices when they are not specified by a component's layout parameters.

void
setRowOrderPreserved(boolean rowOrderPreserved)

When this property is true, GridLayout is forced to place the row boundaries so that their associated grid indices are in ascending order in the view.

void
setUseDefaultMargins(boolean useDefaultMargins)

When true, GridLayout allocates default margins around children based on the child's visual characteristics.

static GridLayout.Spec
spec(int start)

Return a Spec, spec, where:

static GridLayout.Spec
spec(int start, GridLayout.Alignment alignment)

Return a Spec, spec, where:

static GridLayout.Spec
spec(int start, int size)

Return a Spec, spec, where:

static GridLayout.Spec
spec(int start, float weight)

Equivalent to: spec(start, 1, weight).

static GridLayout.Spec
spec(int start, GridLayout.Alignment alignment, float weight)

Equivalent to: spec(start, 1, alignment, weight).

static GridLayout.Spec
spec(int start, int size, GridLayout.Alignment alignment)

Equivalent to: spec(start, size, alignment, 0f).

static GridLayout.Spec
spec(int start, int size, float weight)

Equivalent to: spec(start, 1, default_alignment, weight) - where default_alignment is specified in android.widget.GridLayout.LayoutParams.

static GridLayout.Spec
spec(int start, int size, GridLayout.Alignment alignment, float weight)

Return a Spec, spec, where:

Protected methods

boolean
GridLayout.LayoutParams
GridLayout.LayoutParams
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthSpec, int heightSpec)

Inherited Constants

From android.view.View
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final int
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
static final String
static final String
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
KEEP_SCREEN_ON = 67108864
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
NO_ID = -1
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final String
VIEW_LOG_TAG = "View"
static final int
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
From android.view.ViewGroup
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

Inherited methods

From android.view.View
void
void
void
ViewPropertyAnimator
void
void
boolean
void
void

This method is deprecated.

void
boolean
boolean
boolean
boolean
boolean
canScrollHorizontally(int direction)
boolean
canScrollVertically(int direction)
final void
void
final void
boolean
void
void
static int
combineMeasuredStates(int curState, int newState)
int
int
int
void
WindowInsets
int
int
int
AccessibilityNodeInfo
void
void

This method is deprecated.

boolean
boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
boolean
dispatchNestedPreFling(float velocityX, float velocityY)
boolean
dispatchNestedPrePerformAccessibilityAction(
    int action,
    Bundle arguments
)
boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    int[] consumed,
    int[] offsetInWindow
)
boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int[] offsetInWindow
)
boolean
void
draw(Canvas canvas)
void
drawableHotspotChanged(float x, float y)
final OnBackInvokedDispatcher
final T
<T extends View> findViewById(int id)
final T
<T extends View> findViewWithTag(Object tag)
boolean

This method is deprecated.

void
forceHasOverlappingRendering(boolean hasOverlappingRendering)
void
void
generateDisplayHash(
    String hashAlgorithm,
    Rect bounds,
    Executor executor,
    DisplayHashResultCallback callback
)
static int
View.AccessibilityDelegate
int
AccessibilityNodeProvider
CharSequence
int
int
String
String
float
Animation
Matrix
IBinder
int[]
Map<IntegerInteger>
String[]
final AutofillId
int
AutofillValue
Drawable
BlendMode
ColorStateList
PorterDuff.Mode
int
final int
float
int
float
Rect
boolean
final boolean
final ContentCaptureSession
CharSequence
final Context
ContextMenu.ContextMenuInfo
final boolean
static int
getDefaultSize(int size, int measureSpec)
Display
final int[]
Bitmap

This method is deprecated.

int

This method is deprecated.

int

This method is deprecated.

void
long
float
int
boolean
boolean
int
ArrayList<View>
getFocusables(int direction)
void
Drawable
int
BlendMode
ColorStateList
PorterDuff.Mode
boolean
getGlobalVisibleRect(Rect r, Point globalOffset)
Handler
float
float
float
float
Runnable
final boolean
final int
void
getHitRect(Rect outRect)
int
int
Drawable
Drawable
int
int
int
int
boolean
KeyEvent.DispatcherState
int
int
int
ViewGroup.LayoutParams
final int
float
int
final boolean
void
getLocationInSurface(int[] location)
void
getLocationInWindow(int[] outLocation)
void
getLocationOnScreen(int[] outLocation)
Matrix
final int
final int
final int
final int
final int
int
int
int
int
int
int
int
int
View.OnFocusChangeListener
int
ViewOutlineProvider
int
int
ViewOverlay
int
int
int
int
int
int
final ViewParent
ViewParent
float
float
PointerIcon
final List<Rect>
String[]
Resources
final boolean
final int
float
int
AttachedSurfaceControl
View
WindowInsets
float
float
float
float
float
int
int
int
int
int
int
final int
final int
int
int
final CharSequence
StateListAnimator
int
int
List<Rect>
int

This method is deprecated.

Object
int
int
CharSequence
final int
float
int
TouchDelegate
ArrayList<View>
float
String
float
float
float
long
int
int
Drawable
Drawable
int
ViewTranslationResponse
ViewTreeObserver
int
final int
int
WindowId
WindowInsetsController
int

This method is deprecated.

IBinder
int
void
float
float
float
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
static View
inflate(Context context, int resource, ViewGroup root)
void

This method is deprecated.

void
void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean

This method is deprecated.

boolean
boolean
final boolean
final boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
final boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
View
keyboardNavigationClusterSearch(View currentCluster, int direction)
final void
measure(int widthMeasureSpec, int heightMeasureSpec)
static int[]
mergeDrawableStates(int[] baseState, int[] additionalState)
void
offsetLeftAndRight(int offset)
void
offsetTopAndBottom(int offset)
void
void
WindowInsets
void
boolean
boolean
void
void
InputConnection
void
onCreateViewTranslationRequest(
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onCreateVirtualViewTranslationRequests(
    long[] virtualIds,
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onDisplayHint(int hint)
boolean
void
onDraw(Canvas canvas)
void
final void
boolean
void
void
void
onFocusChanged(
    boolean gainFocus,
    int direction,
    Rect previouslyFocusedRect
)
boolean
void
onHoverChanged(boolean hovered)
boolean
void
void
boolean
onKeyDown(int keyCode, KeyEvent event)
boolean
onKeyLongPress(int keyCode, KeyEvent event)
boolean
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
boolean
onKeyPreIme(int keyCode, KeyEvent event)
boolean
onKeyShortcut(int keyCode, KeyEvent event)
boolean
onKeyUp(int keyCode, KeyEvent event)
void
onOverScrolled(
    int scrollX,
    int scrollY,
    boolean clampedX,
    boolean clampedY
)
void
onPointerCaptureChange(boolean hasCapture)
void
void
onProvideAutofillStructure(ViewStructure structure, int flags)
void
void
void
void
ContentInfo
void
void
onRtlPropertiesChanged(int layoutDirection)
Parcelable
void
onScreenStateChanged(int screenState)
void
onScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
onScrollChanged(int l, int t, int oldl, int oldt)
boolean
onSetAlpha(int alpha)
void
onSizeChanged(int w, int h, int oldw, int oldh)
void
boolean
boolean
void
void
void
onVisibilityAggregated(boolean isVisible)
void
onVisibilityChanged(View changedView, int visibility)
void
onWindowFocusChanged(boolean hasWindowFocus)
void

This method is deprecated.

void
onWindowVisibilityChanged(int visibility)
boolean
overScrollBy(
    int deltaX,
    int deltaY,
    int scrollX,
    int scrollY,
    int scrollRangeX,
    int scrollRangeY,
    int maxOverScrollX,
    int maxOverScrollY,
    boolean isTouchEvent
)
boolean
performAccessibilityAction(int action, Bundle arguments)
boolean
boolean
performContextClick(float x, float y)
boolean
performHapticFeedback(int feedbackConstant)
boolean
ContentInfo
void
playSoundEffect(int soundConstant)
boolean
post(Runnable action)
boolean
postDelayed(Runnable action, long delayMillis)
void
void
postInvalidateDelayed(long delayMilliseconds)
void
void
void
postOnAnimationDelayed(Runnable action, long delayMillis)
void
void
boolean
void
void
void
void
void

This method is deprecated.

final boolean
void
boolean
final void
final T
<T extends View> requireViewById(int id)
void
static int
resolveSize(int size, int measureSpec)
static int
resolveSizeAndState(int size, int measureSpec, int childMeasuredState)
void
final void
saveAttributeDataForStyleable(
    Context context,
    int[] styleable,
    AttributeSet attrs,
    TypedArray t,
    int defStyleAttr,
    int defStyleRes
)
void
void
scheduleDrawable(Drawable who, Runnable what, long when)
void
scrollBy(int x, int y)
void
scrollTo(int x, int y)
void
sendAccessibilityEvent(int eventType)
void
void
setAccessibilityDataSensitive(int accessibilityDataSensitive)
void
void
setAccessibilityHeading(boolean isHeading)
void
void
setAccessibilityPaneTitle(CharSequence accessibilityPaneTitle)
void
void
void
setActivated(boolean activated)
void
setAllowClickWhenDisabled(boolean clickableWhenDisabled)
void
void
void
setAlpha(float alpha)
void
void
void
setAutoHandwritingEnabled(boolean enabled)
void
setAutofillHints(String[] autofillHints)
void
void
setBackground(Drawable background)
void
setBackgroundColor(int color)
void

This method is deprecated.

void
void
void
void
final void
setBottom(int bottom)
void
setCameraDistance(float distance)
void
setClickable(boolean clickable)
void
setClipBounds(Rect clipBounds)
void
setClipToOutline(boolean clipToOutline)
void
void
setContentDescription(CharSequence contentDescription)
void
setContextClickable(boolean contextClickable)
void
setDefaultFocusHighlightEnabled(boolean defaultFocusHighlightEnabled)
void

This method is deprecated.

void
setDrawingCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void
setElevation(float elevation)
void
setEnabled(boolean enabled)
void
setFadingEdgeLength(int length)
void
void
setFitsSystemWindows(boolean fitSystemWindows)
void
setFocusable(boolean focusable)
void
setFocusableInTouchMode(boolean focusableInTouchMode)
void
setFocusedByDefault(boolean isFocusedByDefault)
void
setForceDarkAllowed(boolean allow)
void
setForeground(Drawable foreground)
void
setForegroundGravity(int gravity)
void
void
void
void
setHandwritingBoundsOffsets(
    float offsetLeft,
    float offsetTop,
    float offsetRight,
    float offsetBottom
)
void
void
setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
void
setHasTransientState(boolean hasTransientState)
void
setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)
void
setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)
void
void
void
setHovered(boolean hovered)
void
setId(int id)
void
void
void
void
setIsCredential(boolean isCredential)
void
setIsHandwritingDelegate(boolean isHandwritingDelegate)
void
setKeepScreenOn(boolean keepScreenOn)
void
setKeyboardNavigationCluster(boolean isCluster)
void
setLabelFor(int id)
void
void
setLayerType(int layerType, Paint paint)
void
setLayoutDirection(int layoutDirection)
void
final void
setLeft(int left)
final void
setLeftTopRightBottom(int left, int top, int right, int bottom)
void
setLongClickable(boolean longClickable)
final void
setMeasuredDimension(int measuredWidth, int measuredHeight)
void
setMinimumHeight(int minHeight)
void
setMinimumWidth(int minWidth)
void
setNestedScrollingEnabled(boolean enabled)
void
setNextClusterForwardId(int nextClusterForwardId)
void
setNextFocusDownId(int nextFocusDownId)
void
setNextFocusForwardId(int nextFocusForwardId)
void
setNextFocusLeftId(int nextFocusLeftId)
void
setNextFocusRightId(int nextFocusRightId)
void
setNextFocusUpId(int nextFocusUpId)
void
void
void
void
void
void
void
void
void
void
void
void
setOnReceiveContentListener(
    String[] mimeTypes,
    OnReceiveContentListener listener
)
void
void

This method is deprecated.

void
void
void
void
void
setOverScrollMode(int overScrollMode)
void
setPadding(int left, int top, int right, int bottom)
void
setPaddingRelative(int start, int top, int end, int bottom)
void
setPivotX(float pivotX)
void
setPivotY(float pivotY)
void
final void
setPreferKeepClear(boolean preferKeepClear)
final void
void
setPressed(boolean pressed)
void
final void
setRevealOnFocusHint(boolean revealOnFocus)
final void
setRight(int right)
void
setRotation(float rotation)
void
setRotationX(float rotationX)
void
setRotationY(float rotationY)
void
setSaveEnabled(boolean enabled)
void
setSaveFromParentEnabled(boolean enabled)
void
setScaleX(float scaleX)
void
setScaleY(float scaleY)
void
setScreenReaderFocusable(boolean screenReaderFocusable)
void
setScrollBarDefaultDelayBeforeFade(
    int scrollBarDefaultDelayBeforeFade
)
void
setScrollBarFadeDuration(int scrollBarFadeDuration)
void
setScrollBarSize(int scrollBarSize)
void
setScrollBarStyle(int style)
final void
void
void
setScrollContainer(boolean isScrollContainer)
void
setScrollIndicators(int indicators)
void
setScrollX(int value)
void
setScrollY(int value)
void
setScrollbarFadingEnabled(boolean fadeScrollbars)
void
setSelected(boolean selected)
void
setSoundEffectsEnabled(boolean soundEffectsEnabled)
void
void
void
void
setSystemUiVisibility(int visibility)

This method is deprecated.

void
void
setTextAlignment(int textAlignment)
void
setTextDirection(int textDirection)
void
final void
setTop(int top)
void
void
setTransitionAlpha(float alpha)
final void
setTransitionName(String transitionName)
void
setTransitionVisibility(int visibility)
void
setTranslationX(float translationX)
void
setTranslationY(float translationY)
void
setTranslationZ(float translationZ)
void
setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)
void
setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)
void
void
void
void
void
setVisibility(int visibility)
void
setWillNotCacheDrawing(boolean willNotCacheDrawing)

This method is deprecated.

void
setWillNotDraw(boolean willNotDraw)
void
setX(float x)
void
setY(float y)
void
setZ(float z)
boolean
ActionMode
void
final boolean
startDrag(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)

This method is deprecated.

final boolean
startDragAndDrop(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)
boolean
void
String
void
void
void
final void
boolean
boolean

This method is deprecated.

boolean
From android.view.ViewGroup
void
void
addExtraDataToAccessibilityNodeInfo(
    AccessibilityNodeInfo info,
    String extraDataKey,
    Bundle arguments
)
void
addFocusables(ArrayList<View> views, int direction, int focusableMode)
void
boolean
void
void
addView(View child)
boolean
addViewInLayout(View child, int index, ViewGroup.LayoutParams params)
void
attachLayoutAnimationParameters(
    View child,
    ViewGroup.LayoutParams params,
    int index,
    int count
)
void
attachViewToParent(View child, int index, ViewGroup.LayoutParams params)
void
boolean
void
void
childHasTransientStateChanged(
    View child,
    boolean childHasTransientState
)
void
void
void
void
void
debug(int depth)
void
void
void
detachViewsFromParent(int start, int count)
WindowInsets
boolean
void
void
dispatchCreateViewTranslationRequest(
    Map<AutofillId, long[]> viewIds,
    int[] supportedFormats,
    TranslationCapability capability,
    List<ViewTranslationRequest> requests
)
void
boolean
void
void
dispatchDrawableHotspotChanged(float x, float y)
void
void
boolean
boolean
boolean
boolean
boolean
boolean
void
dispatchPointerCaptureChanged(boolean hasCapture)
void
void
void
void
void
dispatchScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
dispatchSetActivated(boolean activated)
void
dispatchSetPressed(boolean pressed)
void
dispatchSetSelected(boolean selected)
void
void

This method is deprecated.

void
boolean
boolean
boolean
dispatchUnhandledMove(View focused, int direction)
void
dispatchVisibilityChanged(View changedView, int visibility)
void
dispatchWindowFocusChanged(boolean hasFocus)
void
void
WindowInsets
WindowInsetsAnimation.Bounds
void

This method is deprecated.

void
boolean
drawChild(Canvas canvas, View child, long drawingTime)
void
void
View
OnBackInvokedDispatcher
void
findViewsWithText(
    ArrayList<View> outViews,
    CharSequence text,
    int flags
)
View
focusSearch(View focused, int direction)
void
boolean
CharSequence
View
getChildAt(int index)
int
int
getChildDrawingOrder(int childCount, int drawingPosition)
static int
getChildMeasureSpec(int spec, int padding, int childDimension)
boolean
boolean
getChildVisibleRect(View child, Rect r, Point offset)
boolean
boolean
int
View
LayoutAnimationController
Animation.AnimationListener
int
LayoutTransition
int
ViewGroupOverlay
int

This method is deprecated.

boolean
boolean
boolean
int
final void
invalidateChild(View child, Rect dirty)

This method is deprecated.

ViewParent
invalidateChildInParent(int[] location, Rect dirty)

This method is deprecated.

boolean

This method is deprecated.

boolean

This method is deprecated.

boolean
boolean

This method is deprecated.

boolean
boolean
boolean
void
final void
layout(int l, int t, int r, int b)
void
measureChild(
    View child,
    int parentWidthMeasureSpec,
    int parentHeightMeasureSpec
)
void
measureChildWithMargins(
    View child,
    int parentWidthMeasureSpec,
    int widthUsed,
    int parentHeightMeasureSpec,
    int heightUsed
)
void
measureChildren(int widthMeasureSpec, int heightMeasureSpec)
void
notifySubtreeAccessibilityStateChanged(
    View child,
    View source,
    int changeType
)
final void
final void
void
int[]
onCreateDrawableState(int extraSpace)
void
void
boolean
boolean
boolean
onNestedFling(
    View target,
    float velocityX,
    float velocityY,
    boolean consumed
)
boolean
onNestedPreFling(View target, float velocityX, float velocityY)
boolean
onNestedPrePerformAccessibilityAction(
    View target,
    int action,
    Bundle args
)
void
onNestedPreScroll(View target, int dx, int dy, int[] consumed)
void
onNestedScroll(
    View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed
)
void
onNestedScrollAccepted(View child, View target, int axes)
boolean
onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
boolean
PointerIcon
onResolvePointerIcon(MotionEvent event, int pointerIndex)
boolean
onStartNestedScroll(View child, View target, int nestedScrollAxes)
void
void
void
void
void
void
void
removeDetachedView(View child, boolean animate)
void
void
removeViewAt(int index)
void
void
removeViews(int start, int count)
void
removeViewsInLayout(int start, int count)
void
requestChildFocus(View child, View focused)
boolean
requestChildRectangleOnScreen(
    View child,
    Rect rectangle,
    boolean immediate
)
void
requestDisallowInterceptTouchEvent(boolean disallowIntercept)
boolean
requestFocus(int direction, Rect previouslyFocusedRect)
boolean
void
boolean
void
void
setAddStatesFromChildren(boolean addsStates)
void

This method is deprecated.

void
setAnimationCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void

This method is deprecated.

void
setClipChildren(boolean clipChildren)
void
setClipToPadding(boolean clipToPadding)
void
setDescendantFocusability(int focusability)
void
void
void
setLayoutMode(int layoutMode)
void
void
void
void
setPersistentDrawingCache(int drawingCacheToKeep)

This method is deprecated.

void
void
setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus)
void
setTransitionGroup(boolean isTransitionGroup)
void
boolean
boolean
ActionMode
startActionModeForChild(
    View originalView,
    ActionMode.Callback callback
)
void
void
void
suppressLayout(boolean suppress)
void

Constants

ALIGN_BOUNDS

Added in 1.0.0
public static final int ALIGN_BOUNDS = 0

This constant is an alignmentMode. When the alignmentMode is set to ALIGN_BOUNDS, alignment is made between the edges of each component's raw view boundary: i.e. the area delimited by the component's: top, left, bottom and right properties.

For example, when GridLayout is in ALIGN_BOUNDS mode, children that belong to a row group that uses TOP alignment will all return the same value when their getTop method is called.

See also
setAlignmentMode

ALIGN_MARGINS

Added in 1.0.0
public static final int ALIGN_MARGINS = 1

This constant is an alignmentMode. When the alignmentMode is set to ALIGN_MARGINS, the bounds of each view are extended outwards, according to their margins, before the edges of the resulting rectangle are aligned.

For example, when GridLayout is in ALIGN_MARGINS mode, the quantity top - layoutParams.topMargin is the same for all children that belong to a row group that uses TOP alignment.

See also
setAlignmentMode

BASELINE

Added in 1.0.0
public static final GridLayout.Alignment BASELINE

Indicates that a view should be aligned with the baselines of the other views in its cell group. This constant may only be used as an alignment in rowSpecs.

See also
getBaseline

BOTTOM

Added in 1.0.0
public static final GridLayout.Alignment BOTTOM

Indicates that a view should be aligned with the bottom edges of the other views in its cell group.

CENTER

Added in 1.0.0
public static final GridLayout.Alignment CENTER

Indicates that a view should be centered with the other views in its cell group. This constant may be used in both rowSpecs and columnSpecs.

END

Added in 1.0.0
public static final GridLayout.Alignment END

Indicates that a view should be aligned with the end edges of the other views in its cell group.

FILL

Added in 1.0.0
public static final GridLayout.Alignment FILL

Indicates that a view should expanded to fit the boundaries of its cell group. This constant may be used in both rowSpecs and columnSpecs.

HORIZONTAL

Added in 1.0.0
public static final int HORIZONTAL = 0

The horizontal orientation.

LEFT

Added in 1.0.0
public static final GridLayout.Alignment LEFT

Indicates that a view should be aligned with the left edges of the other views in its cell group.

RIGHT

Added in 1.0.0
public static final GridLayout.Alignment RIGHT

Indicates that a view should be aligned with the right edges of the other views in its cell group.

START

Added in 1.0.0
public static final GridLayout.Alignment START

Indicates that a view should be aligned with the start edges of the other views in its cell group.

TOP

Added in 1.0.0
public static final GridLayout.Alignment TOP

Indicates that a view should be aligned with the top edges of the other views in its cell group.

UNDEFINED

Added in 1.0.0
public static final int UNDEFINED = -2147483648

The constant used to indicate that a value is undefined. Fields can use this value to indicate that their values have not yet been set. Similarly, methods can return this value to indicate that there is no suitable value that the implementation can return. The value used for the constant (currently MIN_VALUE) is intended to avoid confusion between valid values whose sign may not be known.

VERTICAL

Added in 1.0.0
public static final int VERTICAL = 1

The vertical orientation.

Public constructors

GridLayout

Added in 1.0.0
public GridLayout(Context context)

GridLayout

Added in 1.0.0
public GridLayout(Context context, AttributeSet attrs)

GridLayout

Added in 1.0.0
public GridLayout(Context context, AttributeSet attrs, int defStyle)

Public methods

generateLayoutParams

Added in 1.0.0
public GridLayout.LayoutParams generateLayoutParams(AttributeSet attrs)

getAlignmentMode

Added in 1.0.0
public int getAlignmentMode()

Returns the alignment mode.

name android:alignmentMode

Returns
int

the alignment mode; either ALIGN_BOUNDS or ALIGN_MARGINS

getColumnCount

Added in 1.0.0
public int getColumnCount()

Returns the current number of columns. This is either the last value that was set with setColumnCount or, if no such value was set, the maximum value of each the upper bounds defined in columnSpec.

name android:columnCount

Returns
int

the current number of columns

getOrientation

Added in 1.0.0
public int getOrientation()

Returns the current orientation.

name android:orientation

Returns
int

either HORIZONTAL or VERTICAL

See also
setOrientation

getPrinter

Added in 1.0.0
public Printer getPrinter()

Return the printer that will log diagnostics from this layout.

Returns
Printer

the printer associated with this view

See also
setPrinter

getRowCount

Added in 1.0.0
public int getRowCount()

Returns the current number of rows. This is either the last value that was set with setRowCount or, if no such value was set, the maximum value of each the upper bounds defined in rowSpec.

name android:rowCount

Returns
int

the current number of rows

See also
setRowCount
rowSpec

getUseDefaultMargins

Added in 1.0.0
public boolean getUseDefaultMargins()

Returns whether or not this GridLayout will allocate default margins when no corresponding layout parameters are defined.

name android:useDefaultMargins

Returns
boolean

true if default margins should be allocated

isColumnOrderPreserved

Added in 1.0.0
public boolean isColumnOrderPreserved()

Returns whether or not column boundaries are ordered by their grid indices.

name android:columnOrderPreserved

Returns
boolean

true if column boundaries must appear in the order of their indices, false otherwise

isRowOrderPreserved

Added in 1.0.0
public boolean isRowOrderPreserved()

Returns whether or not row boundaries are ordered by their grid indices.

name android:rowOrderPreserved

Returns
boolean

true if row boundaries must appear in the order of their indices, false otherwise

requestLayout

public void requestLayout()

setAlignmentMode

Added in 1.0.0
public void setAlignmentMode(int alignmentMode)

Sets the alignment mode to be used for all of the alignments between the children of this container.

The default value of this property is ALIGN_MARGINS.

name android:alignmentMode

Parameters
int alignmentMode

either ALIGN_BOUNDS or ALIGN_MARGINS

setColumnCount

Added in 1.0.0
public void setColumnCount(int columnCount)

ColumnCount is used only to generate default column/column indices when they are not specified by a component's layout parameters.

name android:columnCount

Parameters
int columnCount

the number of columns.

setColumnOrderPreserved

Added in 1.0.0
public void setColumnOrderPreserved(boolean columnOrderPreserved)

When this property is true, GridLayout is forced to place the column boundaries so that their associated grid indices are in ascending order in the view.

When this property is false GridLayout is at liberty to place the horizontal column boundaries in whatever order best fits the given constraints.

The default value of this property is true.

name android:columnOrderPreserved

Parameters
boolean columnOrderPreserved

use true to force GridLayout to respect the order of column boundaries.

setOrientation

Added in 1.0.0
public void setOrientation(int orientation)

GridLayout uses the orientation property for two purposes:

  • To control the 'direction' in which default row/column indices are generated when they are not specified in a component's layout parameters.
  • To control which axis should be processed first during the layout operation: when orientation is HORIZONTAL the horizontal axis is laid out first.
The order in which axes are laid out is important if, for example, the height of one of GridLayout's children is dependent on its width - and its width is, in turn, dependent on the widths of other components.

If your layout contains a android.widget.TextView (or derivative: Button, EditText, CheckBox, etc.) which is in multi-line mode (the default) it is normally best to leave GridLayout's orientation as HORIZONTAL - because TextView is capable of deriving its height for a given width, but not the other way around.

Other than the effects above, orientation does not affect the actual layout operation of GridLayout, so it's fine to leave GridLayout in HORIZONTAL mode even if the height of the intended layout greatly exceeds its width.

The default value of this property is HORIZONTAL.

name android:orientation

Parameters
int orientation

either HORIZONTAL or VERTICAL

See also
getOrientation

setPrinter

Added in 1.0.0
public void setPrinter(Printer printer)

Set the printer that will log diagnostics from this layout. The default value is created by android.util.LogPrinter.

Parameters
Printer printer

the printer associated with this layout

See also
getPrinter

setRowCount

Added in 1.0.0
public void setRowCount(int rowCount)

RowCount is used only to generate default row/column indices when they are not specified by a component's layout parameters.

name android:rowCount

Parameters
int rowCount

the number of rows

See also
getRowCount
rowSpec

setRowOrderPreserved

Added in 1.0.0
public void setRowOrderPreserved(boolean rowOrderPreserved)

When this property is true, GridLayout is forced to place the row boundaries so that their associated grid indices are in ascending order in the view.

When this property is false GridLayout is at liberty to place the vertical row boundaries in whatever order best fits the given constraints.

The default value of this property is true.

name android:rowOrderPreserved

Parameters
boolean rowOrderPreserved

true to force GridLayout to respect the order of row boundaries

setUseDefaultMargins

Added in 1.0.0
public void setUseDefaultMargins(boolean useDefaultMargins)

When true, GridLayout allocates default margins around children based on the child's visual characteristics. Each of the margins so defined may be independently overridden by an assignment to the appropriate layout parameter.

When false, the default value of all margins is zero.

When setting to true, consider setting the value of the alignmentMode property to ALIGN_BOUNDS.

The default value of this property is false.

name android:useDefaultMargins

Parameters
boolean useDefaultMargins

use true to make GridLayout allocate default margins

spec

Added in 1.0.0
public static GridLayout.Spec spec(int start)

Return a Spec, spec, where:

  • spec.span = [start, start + 1]

To leave the start index undefined, use the value UNDEFINED.

Parameters
int start

the start index

See also
spec

spec

Added in 1.0.0
public static GridLayout.Spec spec(int start, GridLayout.Alignment alignment)

Return a Spec, spec, where:

  • spec.span = [start, start + 1]
  • spec.alignment = alignment

To leave the start index undefined, use the value UNDEFINED.

Parameters
int start

the start index

GridLayout.Alignment alignment

the alignment

See also
spec

spec

Added in 1.0.0
public static GridLayout.Spec spec(int start, int size)

Return a Spec, spec, where:

  • spec.span = [start, start + size]

To leave the start index undefined, use the value UNDEFINED.

Parameters
int start

the start

int size

the size

See also
spec

spec

Added in 1.0.0
public static GridLayout.Spec spec(int start, float weight)

Equivalent to: spec(start, 1, weight).

Parameters
int start

the start

float weight

the weight

spec

Added in 1.0.0
public static GridLayout.Spec spec(int start, GridLayout.Alignment alignment, float weight)

Equivalent to: spec(start, 1, alignment, weight).

Parameters
int start

the start

GridLayout.Alignment alignment

the alignment

float weight

the weight

spec

Added in 1.0.0
public static GridLayout.Spec spec(int start, int size, GridLayout.Alignment alignment)

Equivalent to: spec(start, size, alignment, 0f).

Parameters
int start

the start

int size

the size

GridLayout.Alignment alignment

the alignment

spec

Added in 1.0.0
public static GridLayout.Spec spec(int start, int size, float weight)

Equivalent to: spec(start, 1, default_alignment, weight) - where default_alignment is specified in android.widget.GridLayout.LayoutParams.

Parameters
int start

the start

int size

the size

float weight

the weight

spec

Added in 1.0.0
public static GridLayout.Spec spec(int start, int size, GridLayout.Alignment alignment, float weight)

Return a Spec, spec, where:

  • spec.span = [start, start + size]
  • spec.alignment = alignment
  • spec.weight = weight

To leave the start index undefined, use the value UNDEFINED.

Parameters
int start

the start

int size

the size

GridLayout.Alignment alignment

the alignment

float weight

the weight

Protected methods

checkLayoutParams

protected boolean checkLayoutParams(ViewGroup.LayoutParams p)

generateDefaultLayoutParams

Added in 1.0.0
protected GridLayout.LayoutParams generateDefaultLayoutParams()

generateLayoutParams

Added in 1.0.0
protected GridLayout.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp)

onLayout

protected void onLayout(boolean changed, int left, int top, int right, int bottom)

onMeasure

protected void onMeasure(int widthSpec, int heightSpec)