View.MeasureSpec
public
static
class
View.MeasureSpec
extends Object
java.lang.Object | |
↳ | android.view.View.MeasureSpec |
A MeasureSpec encapsulates the layout requirements passed from parent to child. Each MeasureSpec represents a requirement for either the width or the height. A MeasureSpec is comprised of a size and a mode. There are three possible modes:
- UNSPECIFIED
- The parent has not imposed any constraint on the child. It can be whatever size it wants.
- EXACTLY
- The parent has determined an exact size for the child. The child is going to be given those bounds regardless of how big it wants to be.
- AT_MOST
- The child can be as large as it wants up to the specified size.
Summary
Constants | |
---|---|
int |
AT_MOST
Measure specification mode: The child can be as large as it wants up to the specified size. |
int |
EXACTLY
Measure specification mode: The parent has determined an exact size for the child. |
int |
UNSPECIFIED
Measure specification mode: The parent has not imposed any constraint on the child. |
Public constructors | |
---|---|
View.MeasureSpec()
|
Public methods | |
---|---|
static
int
|
getMode(int measureSpec)
Extracts the mode from the supplied measure specification. |
static
int
|
getSize(int measureSpec)
Extracts the size from the supplied measure specification. |
static
int
|
makeMeasureSpec(int size, int mode)
Creates a measure specification based on the supplied size and mode. |
static
String
|
toString(int measureSpec)
Returns a String representation of the specified measure specification. |
Inherited methods | |
---|---|
Constants
AT_MOST
int AT_MOST
Measure specification mode: The child can be as large as it wants up to the specified size.
Constant Value: -2147483648 (0x80000000)
EXACTLY
int EXACTLY
Measure specification mode: The parent has determined an exact size for the child. The child is going to be given those bounds regardless of how big it wants to be.
Constant Value: 1073741824 (0x40000000)
UNSPECIFIED
int UNSPECIFIED
Measure specification mode: The parent has not imposed any constraint on the child. It can be whatever size it wants.
Constant Value: 0 (0x00000000)
Public constructors
Public methods
getMode
int getMode (int measureSpec)
Extracts the mode from the supplied measure specification.
Parameters | |
---|---|
measureSpec |
int : the measure specification to extract the mode from |
Returns | |
---|---|
int |
UNSPECIFIED ,
AT_MOST or
EXACTLY
|
getSize
int getSize (int measureSpec)
Extracts the size from the supplied measure specification.
Parameters | |
---|---|
measureSpec |
int : the measure specification to extract the size from |
Returns | |
---|---|
int |
the size in pixels defined in the supplied measure specification |
makeMeasureSpec
int makeMeasureSpec (int size, int mode)
Creates a measure specification based on the supplied size and mode. The mode must always be one of the following:
Note: On API level 17 and lower, makeMeasureSpec's
implementation was such that the order of arguments did not matter
and overflow in either value could impact the resulting MeasureSpec.
RelativeLayout
was affected by this bug.
Apps targeting API levels greater than 17 will get the fixed, more strict
behavior.
Parameters | |
---|---|
size |
int : the size of the measure specificationValue is 1073741823 or less. |
mode |
int : the mode of the measure specification |
Returns | |
---|---|
int |
the measure specification based on size and mode |
toString
String toString (int measureSpec)
Returns a String representation of the specified measure specification.
Parameters | |
---|---|
measureSpec |
int : the measure specification to convert to a String |
Returns | |
---|---|
String |
a String with the following format: "MeasureSpec: MODE SIZE" |
Annotations
Interfaces
- ActionMode.Callback
- ActionProvider.VisibilityListener
- Choreographer.FrameCallback
- CollapsibleActionView
- ContextMenu
- ContextMenu.ContextMenuInfo
- GestureDetector.OnContextClickListener
- GestureDetector.OnDoubleTapListener
- GestureDetector.OnGestureListener
- InputQueue.Callback
- KeyEvent.Callback
- LayoutInflater.Factory
- LayoutInflater.Factory2
- LayoutInflater.Filter
- Menu
- MenuItem
- MenuItem.OnActionExpandListener
- MenuItem.OnMenuItemClickListener
- PixelCopy.OnPixelCopyFinishedListener
- ScaleGestureDetector.OnScaleGestureListener
- SubMenu
- SurfaceHolder
- SurfaceHolder.Callback
- SurfaceHolder.Callback2
- TextureView.SurfaceTextureListener
- View.OnApplyWindowInsetsListener
- View.OnAttachStateChangeListener
- View.OnCapturedPointerListener
- View.OnClickListener
- View.OnContextClickListener
- View.OnCreateContextMenuListener
- View.OnDragListener
- View.OnFocusChangeListener
- View.OnGenericMotionListener
- View.OnHoverListener
- View.OnKeyFallbackListener
- View.OnKeyListener
- View.OnLayoutChangeListener
- View.OnLongClickListener
- View.OnScrollChangeListener
- View.OnSystemUiVisibilityChangeListener
- View.OnTouchListener
- ViewGroup.OnHierarchyChangeListener
- ViewManager
- ViewParent
- ViewStub.OnInflateListener
- ViewTreeObserver.OnDrawListener
- ViewTreeObserver.OnGlobalFocusChangeListener
- ViewTreeObserver.OnGlobalLayoutListener
- ViewTreeObserver.OnPreDrawListener
- ViewTreeObserver.OnScrollChangedListener
- ViewTreeObserver.OnTouchModeChangeListener
- ViewTreeObserver.OnWindowAttachListener
- ViewTreeObserver.OnWindowFocusChangeListener
- Window.Callback
- Window.OnFrameMetricsAvailableListener
- Window.OnRestrictedCaptionAreaChangedListener
- WindowManager
Classes
- AbsSavedState
- ActionMode
- ActionMode.Callback2
- ActionProvider
- Choreographer
- ContextThemeWrapper
- Display
- Display.HdrCapabilities
- Display.Mode
- DisplayCutout
- DragAndDropPermissions
- DragEvent
- FocusFinder
- FrameMetrics
- FrameStats
- GestureDetector
- GestureDetector.SimpleOnGestureListener
- Gravity
- HapticFeedbackConstants
- InputDevice
- InputDevice.MotionRange
- InputEvent
- InputQueue
- KeyboardShortcutGroup
- KeyboardShortcutInfo
- KeyCharacterMap
- KeyCharacterMap.KeyData
- KeyEvent
- KeyEvent.DispatcherState
- LayoutInflater
- MenuInflater
- MotionEvent
- MotionEvent.PointerCoords
- MotionEvent.PointerProperties
- OrientationEventListener
- OrientationListener
- PixelCopy
- PointerIcon
- ScaleGestureDetector
- ScaleGestureDetector.SimpleOnScaleGestureListener
- SearchEvent
- SoundEffectConstants
- Surface
- SurfaceView
- TextureView
- TouchDelegate
- VelocityTracker
- View
- View.AccessibilityDelegate
- View.BaseSavedState
- View.DragShadowBuilder
- View.MeasureSpec
- ViewAnimationUtils
- ViewConfiguration
- ViewDebug
- ViewGroup
- ViewGroup.LayoutParams
- ViewGroup.MarginLayoutParams
- ViewGroupOverlay
- ViewOutlineProvider
- ViewOverlay
- ViewPropertyAnimator
- ViewStructure
- ViewStructure.HtmlInfo
- ViewStructure.HtmlInfo.Builder
- ViewStub
- ViewTreeObserver
- Window
- WindowAnimationFrameStats
- WindowContentFrameStats
- WindowId
- WindowId.FocusObserver
- WindowInsets
- WindowManager.LayoutParams
Enums
Exceptions