public class GridLayout extends ViewGroup
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).
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.
orientation
,
rowCount
and
columnCount
properties.
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.
A child's ability to stretch is inferred from the alignment properties of
its row and column groups (which are typically set by setting the
gravity
property of the child's layout parameters).
If alignment was defined along a given axis then the component
is taken as flexible in that direction. If no 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 gravity. To prevent a column from stretching, ensure that one of the components in the column does not define 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.
LinearLayout.LayoutParams.weight
. In general, it is not therefore possible
to configure a GridLayout to distribute excess space between multiple components.
Some common use-cases may nevertheless be accommodated as follows.
To place equal amounts of space around a component in a cell group;
use CENTER
alignment (or gravity
).
For complete control over excess space distribution in a row or column;
use a LinearLayout
subview to hold the components in the associated cell group.
When using either of these techniques, bear in mind that cell groups may be defined to overlap.
See GridLayout.LayoutParams
for a full description of the
layout parameters used by GridLayout.
Modifier and Type | Class and Description |
---|---|
static class |
GridLayout.Alignment
Alignments specify where a view should be placed within a cell group and
what size it should be.
|
static class |
GridLayout.LayoutParams
Layout information associated with each of the children of a GridLayout.
|
static class |
GridLayout.Spec
A Spec defines the horizontal or vertical characteristics of a group of
cells.
|
ViewGroup.MarginLayoutParams, ViewGroup.OnHierarchyChangeListener
View.AccessibilityDelegate, View.BaseSavedState, View.DragShadowBuilder, View.MeasureSpec, View.OnAttachStateChangeListener, View.OnClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnSystemUiVisibilityChangeListener, View.OnTouchListener
Modifier and Type | Field and Description |
---|---|
static int |
ALIGN_BOUNDS
This constant is an
alignmentMode . |
static int |
ALIGN_MARGINS
This constant is an
alignmentMode . |
static GridLayout.Alignment |
BASELINE
Indicates that a view should be aligned with the baselines
of the other views in its cell group.
|
static GridLayout.Alignment |
BOTTOM
Indicates that a view should be aligned with the bottom
edges of the other views in its cell group.
|
static GridLayout.Alignment |
CENTER
Indicates that a view should be centered with the other views in its cell group.
|
static GridLayout.Alignment |
END
Indicates that a view should be aligned with the end
edges of the other views in its cell group.
|
static GridLayout.Alignment |
FILL
Indicates that a view should expanded to fit the boundaries of its cell group.
|
static int |
HORIZONTAL
The horizontal orientation.
|
static GridLayout.Alignment |
LEFT
Indicates that a view should be aligned with the left
edges of the other views in its cell group.
|
static GridLayout.Alignment |
RIGHT
Indicates that a view should be aligned with the right
edges of the other views in its cell group.
|
static GridLayout.Alignment |
START
Indicates that a view should be aligned with the start
edges of the other views in its cell group.
|
static GridLayout.Alignment |
TOP
Indicates that a view should be aligned with the top
edges of the other views in its cell group.
|
static int |
UNDEFINED
The constant used to indicate that a value is undefined.
|
static int |
VERTICAL
The vertical orientation.
|
CLIP_BOUNDS, CLIP_TO_PADDING_MASK, FLAG_DISALLOW_INTERCEPT, FLAG_SUPPORT_STATIC_TRANSFORMATIONS, FLAG_USE_CHILD_DRAWING_ORDER, FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS, mDisappearingChildren, mGroupFlags, mOnHierarchyChangeListener, mPersistentDrawingCache, OPTICAL_BOUNDS, PERSISTENT_ALL_CACHES, PERSISTENT_ANIMATION_CACHE, PERSISTENT_NO_CACHE, PERSISTENT_SCROLLING_CACHE
ALPHA, DEBUG_LAYOUT_PROPERTY, DRAG_FLAG_GLOBAL, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_YES, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, mBottom, mCachingFailed, mContext, mCurrentAnimation, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, mInputEventConsistencyVerifier, mLayoutParams, mLeft, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, mUserPaddingBottom, mUserPaddingLeft, mUserPaddingRight, NO_ID, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, PUBLIC_STATUS_BAR_VISIBILITY_MASK, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, STATUS_BAR_DISABLE_BACK, STATUS_BAR_DISABLE_CLOCK, STATUS_BAR_DISABLE_EXPAND, STATUS_BAR_DISABLE_HOME, STATUS_BAR_DISABLE_NOTIFICATION_ALERTS, STATUS_BAR_DISABLE_NOTIFICATION_ICONS, STATUS_BAR_DISABLE_NOTIFICATION_TICKER, STATUS_BAR_DISABLE_RECENT, STATUS_BAR_DISABLE_SEARCH, STATUS_BAR_DISABLE_SYSTEM_INFO, STATUS_BAR_HIDDEN, STATUS_BAR_VISIBLE, SYSTEM_UI_CLEARABLE_FLAGS, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TRANSLATION_X, TRANSLATION_Y, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y
Constructor and Description |
---|
GridLayout(Context context) |
GridLayout(Context context,
AttributeSet attrs) |
GridLayout(Context context,
AttributeSet attrs,
int defStyle) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkLayoutParams(ViewGroup.LayoutParams p) |
protected GridLayout.LayoutParams |
generateDefaultLayoutParams()
Returns a set of default layout parameters.
|
GridLayout.LayoutParams |
generateLayoutParams(AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
|
protected GridLayout.LayoutParams |
generateLayoutParams(ViewGroup.LayoutParams p)
Returns a safe set of layout parameters based on the supplied layout params.
|
int |
getAlignmentMode()
Returns the alignment mode.
|
int |
getColumnCount()
Returns the current number of columns.
|
int |
getOrientation()
Returns the current orientation.
|
int |
getRowCount()
Returns the current number of rows.
|
boolean |
getUseDefaultMargins()
Returns whether or not this GridLayout will allocate default margins when no
corresponding layout parameters are defined.
|
boolean |
isColumnOrderPreserved()
Returns whether or not column boundaries are ordered by their grid indices.
|
boolean |
isRowOrderPreserved()
Returns whether or not row boundaries are ordered by their grid indices.
|
protected void |
onChildVisibilityChanged(View child,
int oldVisibility,
int newVisibility)
We need to call invalidateStructure() when a child's GONE flag changes state.
|
protected void |
onDebugDraw(Canvas canvas) |
protected void |
onDebugDrawMargins(Canvas canvas) |
void |
onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an
AccessibilityEvent with information about
this View which is the event source. |
void |
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an
AccessibilityNodeInfo with information about this view. |
protected void |
onLayout(boolean changed,
int left,
int top,
int right,
int bottom)
Called from layout when this view should
assign a size and position to each of its children.
|
protected void |
onMeasure(int widthSpec,
int heightSpec)
Measure the view and its content to determine the measured width and the
measured height.
|
protected void |
onSetLayoutParams(View child,
ViewGroup.LayoutParams layoutParams) |
protected void |
onViewAdded(View child) |
protected void |
onViewRemoved(View child) |
void |
requestLayout()
Call this when something has changed which has invalidated the
layout of this view.
|
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:
To control the 'direction' in which default row/column indices are generated
when they are not specified in a component's layout parameters.
|
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:
spec.span = [start, start + 1]
|
static GridLayout.Spec |
spec(int start,
GridLayout.Alignment alignment)
Return a Spec,
spec , where:
spec.span = [start, start + 1]
spec.alignment = alignment
|
static GridLayout.Spec |
spec(int start,
int size)
Return a Spec,
spec , where:
spec.span = [start, start + size]
|
static GridLayout.Spec |
spec(int start,
int size,
GridLayout.Alignment alignment)
Return a Spec,
spec , where:
spec.span = [start, start + size]
spec.alignment = alignment
|
addChildrenForAccessibility, addFocusables, addStatesFromChildren, addTouchables, addView, addView, addView, addView, addView, addViewInLayout, addViewInLayout, attachLayoutAnimationParameters, attachViewToParent, bringChildToFront, canAnimate, childAccessibilityStateChanged, childDrawableStateChanged, childHasTransientStateChanged, cleanupLayoutState, clearChildFocus, clearDisappearingChildren, clearFocus, debug, detachAllViewsFromParent, detachViewFromParent, detachViewFromParent, detachViewsFromParent, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDraw, dispatchFinishTemporaryDetach, dispatchFreezeSelfOnly, dispatchGenericFocusedEvent, dispatchGenericPointerEvent, dispatchGetDisplayList, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchThawSelfOnly, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, drawableStateChanged, drawChild, endViewTransition, findFocus, findViewByPredicateTraversal, findViewsWithText, findViewTraversal, findViewWithTagTraversal, fitSystemWindows, focusableViewAvailable, focusSearch, gatherTransparentRegion, getChildAt, getChildCount, getChildDrawingOrder, getChildMeasureSpec, getChildStaticTransformation, getChildVisibleRect, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getLayoutMode, getLayoutTransition, getPersistentDrawingCache, hasFocus, hasFocusable, hasHoveredChild, hasTransientState, indexOfChild, internalSetPadding, invalidateChild, invalidateChildFast, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, isChildrenDrawingOrderEnabled, isChildrenDrawnWithCacheEnabled, isMotionEventSplittingEnabled, isTransformedTouchPointInView, jumpDrawablesToCurrentState, layout, makeOptionalFitsSystemWindows, measureChild, measureChildren, measureChildWithMargins, offsetChildrenTopAndBottom, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onAnimationEnd, onAnimationStart, onCreateDrawableState, onInterceptHoverEvent, onInterceptTouchEvent, onRequestFocusInDescendants, onRequestSendAccessibilityEvent, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeDetachedView, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestFocus, requestSendAccessibilityEvent, requestTransitionStart, requestTransparentRegion, resetAccessibilityStateChanged, resetResolvedDrawables, resetResolvedLayoutDirection, resetResolvedPadding, resetResolvedTextAlignment, resetResolvedTextDirection, resetRtlProperties, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveTextAlignment, resolveTextDirection, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setChildrenDrawingCacheEnabled, setChildrenDrawingOrderEnabled, setChildrenDrawnWithCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setLayoutMode, setLayoutTransition, setMotionEventSplittingEnabled, setOnHierarchyChangeListener, setPersistentDrawingCache, setStaticTransformationsEnabled, shouldDelayChildPressedState, showContextMenuForChild, startActionModeForChild, startLayoutAnimation, startViewTransition, updateViewLayout
addFocusables, addOnAttachStateChangeListener, addOnLayoutChangeListener, animate, announceForAccessibility, applyDrawableToTransparentRegion, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, cancelLongPress, canHaveDisplayList, canResolveLayoutDirection, canScrollHorizontally, canScrollVertically, checkInputConnectionProxy, clearAccessibilityFocus, clearAnimation, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeOpaqueFlags, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createAccessibilityNodeInfo, createContextMenu, debug, debugIndent, destroyDrawingCache, destroyHardwareResources, dispatchGenericMotionEvent, dispatchPointerEvent, dispatchPopulateAccessibilityEvent, draw, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewWithTag, fitsSystemWindows, focusSearch, forceLayout, generateViewId, getAccessibilityCursorPosition, getAccessibilityDelegate, getAccessibilityNodeProvider, getAccessibilityViewId, getAccessibilityWindowId, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getCameraDistance, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDisplay, getDisplayList, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFadeHeight, getFadeTop, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHardwareRenderer, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getHorizontalScrollFactor, getId, getImportantForAccessibility, getIterableTextForAccessibility, getIteratorForGranularity, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOpticalInsets, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getResources, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTextAlignment, getTextDirection, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getTranslationX, getTranslationY, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getVerticalScrollFactor, getViewRootImpl, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, hackTurnOffWindowResizeAnim, hasOnClickListeners, hasOpaqueScrollbars, hasOverlappingRendering, hasWindowFocus, includeForAccessibility, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, invalidateDrawable, invalidateParentCaches, invalidateParentIfNeeded, isActionableForAccessibility, isActivated, isClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isImportantForAccessibility, isInEditMode, isInScrollingContainer, isInTouchMode, isLayoutDirectionInherited, isLayoutRequested, isLayoutRtl, isLongClickable, isOpaque, isPaddingOffsetRequired, isPaddingRelative, isPressed, isRootNamespace, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isTextAlignmentInherited, isTextDirectionInherited, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, isVisibleToUser, isVisibleToUser, measure, mergeDrawableStates, notifyAccessibilityStateChanged, offsetLeftAndRight, offsetTopAndBottom, onAttachedToWindow, onCheckIsTextEditor, onCloseSystemDialogs, onConfigurationChanged, onCreateContextMenu, onCreateInputConnection, onDetachedFromWindow, onDisplayHint, onDragEvent, onDraw, onDrawHorizontalScrollBar, onDrawScrollBars, onDrawVerticalScrollBar, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onFocusLost, onGenericMotionEvent, onHoverChanged, onHoverEvent, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onOverScrolled, onPopulateAccessibilityEvent, onResolveDrawables, onRestoreInstanceState, onRtlPropertiesChanged, onSaveInstanceState, onScreenStateChanged, onScrollChanged, onSetAlpha, onSizeChanged, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onVisibilityChanged, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, onWindowVisibilityChanged, outputDirtyFlags, overScrollBy, performAccessibilityAction, performButtonActionOnTouchDown, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, recomputePadding, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestAccessibilityFocus, requestFitSystemWindows, requestFocus, requestFocus, requestFocusFromTouch, requestRectangleOnScreen, requestRectangleOnScreen, resetPaddingToInitialValues, resolveSize, resolveSizeAndState, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAccessibilityCursorPosition, setAccessibilityDelegate, setActivated, setAlpha, setAnimation, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBottom, setCameraDistance, setClickable, setContentDescription, setDisabledSystemUiVisibility, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setFrame, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setIsRootNamespace, setKeepScreenOn, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutInsets, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPressed, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setSystemUiVisibility, setTag, setTag, setTagInternal, setTextAlignment, setTextDirection, setTop, setTouchDelegate, setTranslationX, setTranslationY, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, showContextMenu, showContextMenu, startActionMode, startAnimation, startDrag, toString, unscheduleDrawable, unscheduleDrawable, verifyDrawable, willNotCacheDrawing, willNotDraw
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createContextMenu, getParent, getParentForAccessibility, isLayoutRequested, requestFitSystemWindows
public static final int HORIZONTAL
public static final int VERTICAL
public static final int UNDEFINED
Integer.MIN_VALUE
) is
intended to avoid confusion between valid values whose sign may not be known.public static final int ALIGN_BOUNDS
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 View.getTop()
method is called.
setAlignmentMode(int)
,
Constant Field Valuespublic static final int ALIGN_MARGINS
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.
setAlignmentMode(int)
,
Constant Field Valuespublic static final GridLayout.Alignment TOP
public static final GridLayout.Alignment BOTTOM
public static final GridLayout.Alignment START
public static final GridLayout.Alignment END
public static final GridLayout.Alignment LEFT
public static final GridLayout.Alignment RIGHT
public static final GridLayout.Alignment CENTER
rowSpecs
and columnSpecs
.public static final GridLayout.Alignment BASELINE
rowSpecs
.View.getBaseline()
public static final GridLayout.Alignment FILL
rowSpecs
and
columnSpecs
.public GridLayout(Context context, AttributeSet attrs, int defStyle)
public GridLayout(Context context, AttributeSet attrs)
public GridLayout(Context context)
public int getOrientation()
HORIZONTAL
or VERTICAL
setOrientation(int)
public void setOrientation(int orientation)
HORIZONTAL
the horizontal axis is laid out first.
If your layout contains a 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
.
orientation
- either HORIZONTAL
or VERTICAL
getOrientation()
public int getRowCount()
setRowCount(int)
or, if no such value was set, the maximum
value of each the upper bounds defined in GridLayout.LayoutParams.rowSpec
.setRowCount(int)
,
GridLayout.LayoutParams.rowSpec
public void setRowCount(int rowCount)
rowCount
- the number of rowsgetRowCount()
,
GridLayout.LayoutParams.rowSpec
public int getColumnCount()
setColumnCount(int)
or, if no such value was set, the maximum
value of each the upper bounds defined in GridLayout.LayoutParams.columnSpec
.setColumnCount(int)
,
GridLayout.LayoutParams.columnSpec
public void setColumnCount(int columnCount)
columnCount
- the number of columns.getColumnCount()
,
GridLayout.LayoutParams.columnSpec
public boolean getUseDefaultMargins()
true
if default margins should be allocatedsetUseDefaultMargins(boolean)
public void setUseDefaultMargins(boolean useDefaultMargins)
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
.
useDefaultMargins
- use true
to make GridLayout allocate default marginsgetUseDefaultMargins()
,
setAlignmentMode(int)
,
MarginLayoutParams#leftMargin
,
MarginLayoutParams#topMargin
,
MarginLayoutParams#rightMargin
,
MarginLayoutParams#bottomMargin
public int getAlignmentMode()
ALIGN_BOUNDS
or ALIGN_MARGINS
ALIGN_BOUNDS
,
ALIGN_MARGINS
,
setAlignmentMode(int)
public void setAlignmentMode(int alignmentMode)
The default value of this property is ALIGN_MARGINS
.
alignmentMode
- either ALIGN_BOUNDS
or ALIGN_MARGINS
ALIGN_BOUNDS
,
ALIGN_MARGINS
,
getAlignmentMode()
public boolean isRowOrderPreserved()
true
if row boundaries must appear in the order of their indices,
false
otherwisesetRowOrderPreserved(boolean)
public void setRowOrderPreserved(boolean rowOrderPreserved)
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
.
rowOrderPreserved
- true
to force GridLayout to respect the order
of row boundariesisRowOrderPreserved()
public boolean isColumnOrderPreserved()
true
if column boundaries must appear in the order of their indices,
false
otherwisesetColumnOrderPreserved(boolean)
public void setColumnOrderPreserved(boolean columnOrderPreserved)
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
.
columnOrderPreserved
- use true
to force GridLayout to respect the order
of column boundaries.isColumnOrderPreserved()
protected void onSetLayoutParams(View child, ViewGroup.LayoutParams layoutParams)
onSetLayoutParams
in class ViewGroup
protected boolean checkLayoutParams(ViewGroup.LayoutParams p)
ViewGroup
checkLayoutParams
in class ViewGroup
protected GridLayout.LayoutParams generateDefaultLayoutParams()
ViewGroup
ViewGroup.addView(View)
has no layout parameters
already set. If null is returned, an exception is thrown from addView.generateDefaultLayoutParams
in class ViewGroup
public GridLayout.LayoutParams generateLayoutParams(AttributeSet attrs)
ViewGroup
generateLayoutParams
in class ViewGroup
attrs
- the attributes to build the layout parameters fromViewGroup.LayoutParams
or one
of its descendantsprotected GridLayout.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
ViewGroup
ViewGroup.checkLayoutParams(android.view.ViewGroup.LayoutParams)
, this method
is invoked. This method should return a new set of layout params suitable for
this ViewGroup, possibly by copying the appropriate attributes from the
specified set of layout params.generateLayoutParams
in class ViewGroup
p
- The layout parameters to convert into a suitable set of layout parameters
for this ViewGroup.ViewGroup.LayoutParams
or one
of its descendantsprotected void onDebugDrawMargins(Canvas canvas)
onDebugDrawMargins
in class ViewGroup
protected void onDebugDraw(Canvas canvas)
onDebugDraw
in class ViewGroup
protected void onViewAdded(View child)
onViewAdded
in class ViewGroup
protected void onViewRemoved(View child)
onViewRemoved
in class ViewGroup
protected void onChildVisibilityChanged(View child, int oldVisibility, int newVisibility)
onChildVisibilityChanged
in class ViewGroup
child
- The view whose visibility has changedoldVisibility
- The previous visibility value (GONE, INVISIBLE, or VISIBLE).newVisibility
- The new visibility value (GONE, INVISIBLE, or VISIBLE).protected void onMeasure(int widthSpec, int heightSpec)
View
Measure the view and its content to determine the measured width and the
measured height. This method is invoked by View.measure(int, int)
and
should be overriden by subclasses to provide accurate and efficient
measurement of their contents.
CONTRACT: When overriding this method, you
must call View.setMeasuredDimension(int, int)
to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
View.measure(int, int)
. Calling the superclass'
View.onMeasure(int, int)
is a valid use.
The base class implementation of measure defaults to the background size,
unless a larger size is allowed by the MeasureSpec. Subclasses should
override View.onMeasure(int, int)
to provide better measurements of
their content.
If this method is overridden, it is the subclass's responsibility to make
sure the measured height and width are at least the view's minimum height
and width (View.getSuggestedMinimumHeight()
and
View.getSuggestedMinimumWidth()
).
onMeasure
in class View
widthSpec
- horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec
.heightSpec
- vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec
.View.getMeasuredWidth()
,
View.getMeasuredHeight()
,
View.setMeasuredDimension(int, int)
,
View.getSuggestedMinimumHeight()
,
View.getSuggestedMinimumWidth()
,
View.MeasureSpec.getMode(int)
,
View.MeasureSpec.getSize(int)
public void requestLayout()
View
requestLayout
in interface ViewParent
requestLayout
in class View
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
public void onInitializeAccessibilityEvent(AccessibilityEvent event)
View
AccessibilityEvent
with information about
this View which is the event source. In other words, the source of
an accessibility event is the view whose state change triggered firing
the event.
Example: Setting the password property of an event in addition to properties set by the super implementation:
public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); event.setPassword(true); }
If an View.AccessibilityDelegate
has been specified via calling
View.setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.onInitializeAccessibilityEvent(View, AccessibilityEvent)
is responsible for handling this call.
Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.
onInitializeAccessibilityEvent
in class View
event
- The event to initialize.View.sendAccessibilityEvent(int)
,
View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
View
AccessibilityNodeInfo
with information about this view.
The base implementation sets:
AccessibilityNodeInfo.setParent(View)
,AccessibilityNodeInfo.setBoundsInParent(Rect)
,AccessibilityNodeInfo.setBoundsInScreen(Rect)
,AccessibilityNodeInfo.setPackageName(CharSequence)
,AccessibilityNodeInfo.setClassName(CharSequence)
,AccessibilityNodeInfo.setContentDescription(CharSequence)
,AccessibilityNodeInfo.setEnabled(boolean)
,AccessibilityNodeInfo.setClickable(boolean)
,AccessibilityNodeInfo.setFocusable(boolean)
,AccessibilityNodeInfo.setFocused(boolean)
,AccessibilityNodeInfo.setLongClickable(boolean)
,AccessibilityNodeInfo.setSelected(boolean)
,Subclasses should override this method, call the super implementation, and set additional attributes.
If an View.AccessibilityDelegate
has been specified via calling
View.setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)
is responsible for handling this call.
onInitializeAccessibilityNodeInfo
in class View
info
- The instance to initialize.public static GridLayout.Spec spec(int start, int size, GridLayout.Alignment alignment)
spec
, where:
spec.span = [start, start + size]
spec.alignment = alignment
start
- the startsize
- the sizealignment
- the alignmentpublic static GridLayout.Spec spec(int start, GridLayout.Alignment alignment)
spec
, where:
spec.span = [start, start + 1]
spec.alignment = alignment
start
- the start indexalignment
- the alignmentpublic static GridLayout.Spec spec(int start, int size)
spec
, where:
spec.span = [start, start + size]
start
- the startsize
- the sizepublic static GridLayout.Spec spec(int start)
spec
, where:
spec.span = [start, start + 1]
start
- the start index