| java.lang.Object | ||
| ↳ | android.view.View | |
| ↳ | android.view.ViewGroup | |
Known Direct Subclasses
|
Known Indirect Subclasses
|
A ViewGroup is a special view that can contain other views
(called children.) The view group is the base class for layouts and views
containers. This class also defines the
ViewGroup.LayoutParams class which serves as the base
class for layouts parameters.
Also see ViewGroup.LayoutParams for layout attributes.
For more information about creating user interface layouts, read the XML Layouts developer guide.
| Nested Classes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| ViewGroup.LayoutParams | LayoutParams are used by views to tell their parents how they want to be laid out. | ||||||||||
| ViewGroup.MarginLayoutParams | Per-child layout information for layouts that support margins. | ||||||||||
| ViewGroup.OnHierarchyChangeListener | Interface definition for a callback to be invoked when the hierarchy within this view changed. | ||||||||||
| XML Attributes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| android:addStatesFromChildren | Sets whether this ViewGroup's drawable states also include its children's drawable states. | ||||||||||
| android:alwaysDrawnWithCache | Defines whether the ViewGroup should always draw its children using their drawing cache or not. | ||||||||||
| android:animateLayoutChanges | setLayoutTransition(LayoutTransition) | Defines whether changes in layout (caused by adding and removing items) should cause a LayoutTransition to run. | |||||||||
| android:animationCache | Defines whether layout animations should create a drawing cache for their children. | ||||||||||
| android:clipChildren | setClipChildren(boolean) | Defines whether a child is limited to draw inside of its bounds or not. | |||||||||
| android:clipToPadding | setClipToPadding(boolean) | Defines whether the ViewGroup will clip its drawing surface so as to exclude the padding area. | |||||||||
| android:descendantFocusability | Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus. | ||||||||||
| android:layoutAnimation | Defines the layout animation to use the first time the ViewGroup is laid out. | ||||||||||
| android:persistentDrawingCache | Defines the persistence of the drawing cache. | ||||||||||
|
[Expand]
Inherited XML Attributes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.View
| |||||||||||
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int | CLIP_TO_PADDING_MASK | We clip to padding when FLAG_CLIP_TO_PADDING and FLAG_PADDING_NOT_NULL are set at the same time. | |||||||||
| int | FOCUS_AFTER_DESCENDANTS | This view will get focus only if none of its descendants want it. | |||||||||
| int | FOCUS_BEFORE_DESCENDANTS | This view will get focus before any of its descendants. | |||||||||
| int | FOCUS_BLOCK_DESCENDANTS | This view will block any of its descendants from getting focus, even if they are focusable. | |||||||||
| int | PERSISTENT_ALL_CACHES | Used to indicate that all drawing caches should be kept in memory. | |||||||||
| int | PERSISTENT_ANIMATION_CACHE | Used to indicate that the animation drawing cache should be kept in memory. | |||||||||
| int | PERSISTENT_NO_CACHE | Used to indicate that no drawing cache should be kept in memory. | |||||||||
| int | PERSISTENT_SCROLLING_CACHE | Used to indicate that the scrolling drawing cache should be kept in memory. | |||||||||
|
[Expand]
Inherited Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.View
| |||||||||||
|
[Expand]
Inherited Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.View
| |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adds any focusable views that are descendants of this view (possibly
including this view if it is focusable itself) to views.
| |||||||||||
Add any focusable views that are descendants of this view (possibly
including this view if it is focusable itself) to views.
| |||||||||||
Returns whether this ViewGroup's drawable states also include
its children's drawable states.
| |||||||||||
Add any touchable views that are descendants of this view (possibly
including this view if it is touchable itself) to views.
| |||||||||||
Adds a child view with the specified layout parameters.
| |||||||||||
Adds a child view with the specified layout parameters.
| |||||||||||
Adds a child view.
| |||||||||||
Adds a child view.
| |||||||||||
Adds a child view with this ViewGroup's default layout parameters and the
specified width and height.
| |||||||||||
Change the z order of the child so it's on top of all other children
| |||||||||||
If {link #addStatesFromChildren} is true, refreshes this group's
drawable state (to include the states from its children).
| |||||||||||
Called when a child of this parent is giving up focus
| |||||||||||
Removes any pending animations for views that have been removed.
| |||||||||||
Called when this view wants to give up focus.
| |||||||||||
Dispatch a notification about a resource configuration change down
the view hierarchy.
| |||||||||||
Dispatch a hint about whether this view is displayed.
| |||||||||||
Detects if this View is enabled and has a drag event listener.
!!! TODO: write real docs
| |||||||||||
Dispatch a key event to the next view on the focus path.
| |||||||||||
Dispatch a key event before it is processed by any input method
associated with the view hierarchy.
| |||||||||||
Dispatches a key shortcut event.
| |||||||||||
Dispatch setActivated to all of this View's children.
| |||||||||||
Dispatch setSelected to all of this View's children.
| |||||||||||
Dispatch callbacks to
setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener) down
the view hierarchy. | |||||||||||
Pass the touch screen motion event down to the target view, or this
view if it is the target.
| |||||||||||
Pass a trackball motion event down to the focused view.
| |||||||||||
This method is the last chance for the focused view and its ancestors to
respond to an arrow key.
| |||||||||||
Called when the window containing this view gains or loses window focus.
| |||||||||||
Dispatch a window visibility change down the view hierarchy.
| |||||||||||
This method should always be called following an earlier call to
startViewTransition(View). | |||||||||||
Find the view in the hierarchy rooted at this view that currently has
focus.
| |||||||||||
Finds the Views that contain given text.
| |||||||||||
Find the nearest view in the specified direction that wants to take
focus.
| |||||||||||
Tells the parent that a new focusable view has become available.
| |||||||||||
This is used by the RootView to perform an optimization when
the view hierarchy contains one or several SurfaceView.
| |||||||||||
Returns a new set of layout parameters based on the supplied attributes set.
| |||||||||||
Returns the view at the specified position in the group.
| |||||||||||
Returns the number of children in the group.
| |||||||||||
Does the hard part of measureChildren: figuring out the MeasureSpec to
pass to a particular child.
| |||||||||||
Compute the visible part of a rectangular region defined in terms of a child view's
coordinates.
| |||||||||||
Gets the descendant focusability of this view group.
| |||||||||||
Returns the focused child of this view, if any.
| |||||||||||
Returns the layout animation controller used to animate the group's
children.
| |||||||||||
Returns the animation listener to which layout animation events are
sent.
| |||||||||||
Gets the LayoutTransition object for this ViewGroup.
| |||||||||||
Returns an integer indicating what types of drawing caches are kept in memory.
| |||||||||||
Returns true if this view has or contains focus
| |||||||||||
Returns true if this view is focusable or if it contains a reachable View
for which
hasFocusable() returns true.
| |||||||||||
Returns the position in the group of the specified child view.
| |||||||||||
Don't call or override this method.
| |||||||||||
Don't call or override this method.
| |||||||||||
Indicates whether this ViewGroup will always try to draw its children using their
drawing cache.
| |||||||||||
Indicates whether the children's drawing cache is used during a layout
animation.
| |||||||||||
Returns true if MotionEvents dispatched to this ViewGroup can be split to multiple children.
| |||||||||||
Call
Drawable.jumpToCurrentState()
on all Drawable objects associated with this view. | |||||||||||
Assign a size and position to a view and all of its
descendants
This is the second phase of the layout mechanism. | |||||||||||
Offset a rectangle that is in a descendant's coordinate
space into our coordinate space.
| |||||||||||
Offset a rectangle that is in our coordinate space into an ancestor's
coordinate space.
| |||||||||||
Implement this method to intercept hover events before they are handled
by child views.
| |||||||||||
Implement this method to intercept all touch screen motion events.
| |||||||||||
Called when a child has requested sending an
AccessibilityEvent and
gives an opportunity to its parent to augment the event. | |||||||||||
Tell view hierarchy that the global view attributes need to be
re-evaluated.
| |||||||||||
Call this method to remove all child views from the
ViewGroup.
| |||||||||||
Called by a ViewGroup subclass to remove child views from itself,
when it must first know its size on screen before it can calculate how many
child views it will render.
| |||||||||||
Removes the view at the specified position in the group.
| |||||||||||
Removes a view during layout.
| |||||||||||
Removes the specified range of views from the group.
| |||||||||||
Removes a range of views during layout.
| |||||||||||
Called when a child of this parent wants focus
| |||||||||||
Called when a child of this group wants a particular rectangle to be
positioned onto the screen.
| |||||||||||
Called when a child does not want this parent and its ancestors to
intercept touch events with
onInterceptTouchEvent(MotionEvent).
| |||||||||||
Call this to try to give focus to a specific view or to one of its descendants
and give it hints about the direction and a specific rectangle that the focus
is coming from.
Looks for a view to give focus to respecting the setting specified by
getDescendantFocusability(). | |||||||||||
Called by a child to request from its parent to send an
AccessibilityEvent.
| |||||||||||
Called when a child wants the view hierarchy to gather and report
transparent regions to the window compositor.
| |||||||||||
Schedules the layout animation to be played after the next layout pass
of this view group.
| |||||||||||
Sets whether this ViewGroup's drawable states also include
its children's drawable states.
| |||||||||||
Indicates whether this ViewGroup will always try to draw its children using their
drawing cache.
| |||||||||||
Enables or disables the children's drawing cache during a layout animation.
| |||||||||||
By default, children are clipped to their bounds before drawing.
| |||||||||||
By default, children are clipped to the padding of the ViewGroup.
| |||||||||||
Set the descendant focusability of this view group.
| |||||||||||
Sets the layout animation controller used to animate the group's
children after the first layout.
| |||||||||||
Specifies the animation listener to which layout animation events must
be sent.
| |||||||||||
Sets the LayoutTransition object for this ViewGroup.
| |||||||||||
Enable or disable the splitting of MotionEvents to multiple children during touch event
dispatch.
| |||||||||||
Register a callback to be invoked when a child is added to or removed
from this view.
| |||||||||||
Sets the padding.
| |||||||||||
Indicates what types of drawing caches should be kept in memory after
they have been created.
| |||||||||||
Return true if the pressed state should be delayed for children or descendants of this
ViewGroup.
| |||||||||||
Bring up a context menu for the specified view or its ancestors.
| |||||||||||
Start an action mode for the specified view.
| |||||||||||
Runs the layout animation.
| |||||||||||
This method tells the ViewGroup that the given View object, which should have this
ViewGroup as its parent,
should be kept around (re-displayed when the ViewGroup draws its children) even if it
is removed from its parent.
| |||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adds a view during layout.
| |||||||||||
Adds a view during layout.
| |||||||||||
Subclasses should override this method to set layout animation
parameters on the supplied child.
| |||||||||||
Attaches a view to this view group.
| |||||||||||
Indicates whether the view group has the ability to animate its children
after the first layout.
| |||||||||||
Prevents the specified child to be laid out during the next layout pass.
| |||||||||||
Prints information about this view in the log output, with the tag
VIEW_LOG_TAG.
| |||||||||||
Detaches all views from the parent.
| |||||||||||
Detaches a view from its parent.
| |||||||||||
Detaches a view from its parent.
| |||||||||||
Detaches a range of view from their parent.
| |||||||||||
Called by draw to draw the child views.
| |||||||||||
Perform dispatching of a
saveHierarchyState(android.util.SparseArray) freeze()}
to only this view, not to its children. | |||||||||||
Dispatch a generic motion event to the currently focused view.
| |||||||||||
Dispatch a generic motion event to the view under the first pointer.
| |||||||||||
Dispatch a hover event.
| |||||||||||
Called by
restoreHierarchyState(android.util.SparseArray) to retrieve the
state for this view and its children.
| |||||||||||
Called by
saveHierarchyState(android.util.SparseArray) to store the state for
this view and its children.
| |||||||||||
Dispatch setPressed to all of this View's children.
| |||||||||||
Perform dispatching of a
restoreHierarchyState(android.util.SparseArray)
to only this view, not to its children. | |||||||||||
Dispatch a view visibility change down the view hierarchy.
| |||||||||||
Draw one child of this View Group.
| |||||||||||
This function is called whenever the state of the view changes in such
a way that it impacts the state of drawables being shown.
| |||||||||||
Apply the insets for system windows to this view, if the FITS_SYSTEM_WINDOWS flag
is set
| |||||||||||
Returns a set of default layout parameters.
| |||||||||||
Returns a safe set of layout parameters based on the supplied layout params.
| |||||||||||
Returns the index of the child to draw for this iteration.
| |||||||||||
Indicates whether the ViewGroup is drawing its children in the order defined by
getChildDrawingOrder(int, int). | |||||||||||
Indicates whether the ViewGroup is currently drawing its children using
their drawing cache.
| |||||||||||
Ask one of the children of this view to measure itself, taking into
account both the MeasureSpec requirements for this view and its padding.
| |||||||||||
Ask one of the children of this view to measure itself, taking into
account both the MeasureSpec requirements for this view and its padding
and margins.
| |||||||||||
Ask all of the children of this view to measure themselves, taking into
account both the MeasureSpec requirements for this view and its padding.
| |||||||||||
Invoked by a parent ViewGroup to notify the end of the animation
currently associated with this view.
| |||||||||||
Invoked by a parent ViewGroup to notify the start of the animation
currently associated with this view.
| |||||||||||
Generate the new
Drawable state for
this view. | |||||||||||
Called from layout when this view should
assign a size and position to each of its children.
| |||||||||||
Look for a descendant to call
requestFocus() on. | |||||||||||
Finishes the removal of a detached view.
| |||||||||||
Reset the resolved layout direction.
| |||||||||||
Reset resolved text direction.
| |||||||||||
Enables or disables the drawing cache for each child of this view group.
| |||||||||||
Tells the ViewGroup whether to draw its children in the order defined by the method
getChildDrawingOrder(int, int). | |||||||||||
Tells the ViewGroup to draw its children using their drawing cache.
| |||||||||||
When this property is set to true, this ViewGroup supports static transformations on
children; this causes
getChildStaticTransformation(View, android.view.animation.Transformation) to be
invoked when a child is drawn. | |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.View
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
android.graphics.drawable.Drawable.Callback
| |||||||||||
From interface
android.view.KeyEvent.Callback
| |||||||||||
From interface
android.view.ViewManager
| |||||||||||
From interface
android.view.ViewParent
| |||||||||||
From interface
android.view.accessibility.AccessibilityEventSource
| |||||||||||
Sets whether this ViewGroup's drawable states also include its children's drawable states. This is used, for example, to make a group appear to be focused when its child EditText or button is focused.
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form
"@[package:]type:name") or
theme attribute (in the form
"?[package:][type:]name")
containing a value of this type.
This corresponds to the global attribute resource symbol addStatesFromChildren.
Defines whether the ViewGroup should always draw its children using their drawing cache or not. The default value is true.
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form
"@[package:]type:name") or
theme attribute (in the form
"?[package:][type:]name")
containing a value of this type.
This corresponds to the global attribute resource symbol alwaysDrawnWithCache.
Defines whether changes in layout (caused by adding and removing items) should cause a LayoutTransition to run. When this flag is set to true, a default LayoutTransition object will be set on the ViewGroup container and default animations will run when these layout changes occur.
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form
"@[package:]type:name") or
theme attribute (in the form
"?[package:][type:]name")
containing a value of this type.
This corresponds to the global attribute resource symbol animateLayoutChanges.
Defines whether layout animations should create a drawing cache for their children. Enabling the animation cache consumes more memory and requires a longer initialization but provides better performance. The animation cache is enabled by default.
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form
"@[package:]type:name") or
theme attribute (in the form
"?[package:][type:]name")
containing a value of this type.
This corresponds to the global attribute resource symbol animationCache.
Defines whether a child is limited to draw inside of its bounds or not. This is useful with animations that scale the size of the children to more than 100% for instance. In such a case, this property should be set to false to allow the children to draw outside of their bounds. The default value of this property is true.
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form
"@[package:]type:name") or
theme attribute (in the form
"?[package:][type:]name")
containing a value of this type.
This corresponds to the global attribute resource symbol clipChildren.
Defines whether the ViewGroup will clip its drawing surface so as to exclude the padding area. This property is set to true by default.
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form
"@[package:]type:name") or
theme attribute (in the form
"?[package:][type:]name")
containing a value of this type.
This corresponds to the global attribute resource symbol clipToPadding.
Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
Must be one of the following constant values.
| Constant | Value | Description |
|---|---|---|
beforeDescendants | 0 | The ViewGroup will get focus before any of its descendants. |
afterDescendants | 1 | The ViewGroup will get focus only if none of its descendants want it. |
blocksDescendants | 2 | The ViewGroup will block its descendants from receiving focus. |
This corresponds to the global attribute resource symbol descendantFocusability.
Defines the layout animation to use the first time the ViewGroup is laid out. Layout animations can also be started manually after the first layout.
Must be a reference to another resource, in the form "@[+][package:]type:name"
or to a theme attribute in the form "?[package:][type:]name".
This corresponds to the global attribute resource symbol layoutAnimation.
Defines the persistence of the drawing cache. The drawing cache might be enabled by a ViewGroup for all its children in specific situations (for instance during a scrolling.) This property lets you persist the cache in memory after its initial usage. Persisting the cache consumes more memory but may prevent frequent garbage collection is the cache is created over and over again. By default the persistence is set to scrolling.
Must be one or more (separated by '|') of the following constant values.
| Constant | Value | Description |
|---|---|---|
none | 0x0 | The drawing cache is not persisted after use. |
animation | 0x1 | The drawing cache is persisted after a layout animation. |
scrolling | 0x2 | The drawing cache is persisted after a scroll. |
all | 0x3 | The drawing cache is always persisted. |
This corresponds to the global attribute resource symbol persistentDrawingCache.
We clip to padding when FLAG_CLIP_TO_PADDING and FLAG_PADDING_NOT_NULL are set at the same time.
This view will get focus only if none of its descendants want it.
This view will get focus before any of its descendants.
This view will block any of its descendants from getting focus, even if they are focusable.
Used to indicate that all drawing caches should be kept in memory.
Used to indicate that the animation drawing cache should be kept in memory.
Used to indicate that no drawing cache should be kept in memory.
Used to indicate that the scrolling drawing cache should be kept in memory.
Adds any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. This method adds all focusable views regardless if we are in touch mode or only views focusable in touch mode if we are in touch mode depending on the focusable mode paramater.
| views | Focusable views found so far or null if all we are interested is the number of focusables. |
|---|---|
| direction | The direction of the focus. |
| focusableMode | The type of focusables to be added. |
Add any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. If we are in touch mode, only add views that are also focusable in touch mode.
| views | Focusable views found so far |
|---|---|
| direction | The direction of the focus |
Returns whether this ViewGroup's drawable states also include its children's drawable states. This is used, for example, to make a group appear to be focused when its child EditText or button is focused.
Add any touchable views that are descendants of this view (possibly including this view if it is touchable itself) to views.
| views | Touchable views found so far |
|---|
Adds a child view with the specified layout parameters.
| child | the child view to add |
|---|---|
| index | the position at which to add the child |
| params | the layout parameters to set on the child |
Adds a child view with the specified layout parameters.
| child | the child view to add |
|---|---|
| params | the layout parameters to set on the child |
Adds a child view. If no layout parameters are already set on the child, the default parameters for this ViewGroup are set on the child.
| child | the child view to add |
|---|---|
| index | the position at which to add the child |
Adds a child view. If no layout parameters are already set on the child, the default parameters for this ViewGroup are set on the child.
| child | the child view to add |
|---|
Adds a child view with this ViewGroup's default layout parameters and the specified width and height.
| child | the child view to add |
|---|
Change the z order of the child so it's on top of all other children
If {link #addStatesFromChildren} is true, refreshes this group's drawable state (to include the states from its children).
| child | The child whose drawable state has changed. |
|---|
Called when a child of this parent is giving up focus
| child | The view that is giving up focus |
|---|
Removes any pending animations for views that have been removed. Call this if you don't want animations for exiting views to stack up.
Called when this view wants to give up focus. This will cause
onFocusChanged(boolean, int, android.graphics.Rect) to be called.
Dispatch a notification about a resource configuration change down the view hierarchy. ViewGroups should override to route to their children.
| newConfig | The new resource configuration. |
|---|
Dispatch a hint about whether this view is displayed. For instance, when a View moves out of the screen, it might receives a display hint indicating the view is not displayed. Applications should not rely on this hint as there is no guarantee that they will receive one.
Detects if this View is enabled and has a drag event listener.
If both are true, then it calls the drag event listener with the
DragEvent it received. If the drag event listener returns
true, then dispatchDragEvent() returns true.
For all other cases, the method calls the
onDragEvent() drag event handler
method and returns its result.
This ensures that a drag event is always consumed, even if the View does not have a drag event listener. However, if the View has a listener and the listener returns true, then onDragEvent() is not called.
!!! TODO: write real docsDispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.
| event | The key event to be dispatched. |
|---|
Dispatch a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application's UI instead of allowing the IME to see it and close itself.
| event | The key event to be dispatched. |
|---|