java.lang.Object | |||
android.view.View | Drawable.Callback KeyEvent.Callback | ||
android.view.ViewGroup | ViewManager ViewParent |
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.
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. |
Attribute name | Related methods | |
---|---|---|
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. |
Value | ||||
---|---|---|---|---|
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. | 34 | 0x00000022 |
int | FLAG_SUPPORT_STATIC_TRANSFORMATIONS | When set, this ViewGroup supports static transformations on children; this causes getChildStaticTransformation(View, android.view.animation.Transformation) to be invoked when a child is drawn. | 2048 | 0x00000800 |
int | FLAG_USE_CHILD_DRAWING_ORDER | When set, the drawing method will call getChildDrawingOrder(int, int) to get the index of the child to draw for that iteration. | 1024 | 0x00000400 |
int | FOCUS_AFTER_DESCENDANTS | This view will get focus only if none of its descendants want it. | 262144 | 0x00040000 |
int | FOCUS_BEFORE_DESCENDANTS | This view will get focus before any of its descendants. | 131072 | 0x00020000 |
int | FOCUS_BLOCK_DESCENDANTS | This view will block any of its descendants from getting focus, even if they are focusable. | 393216 | 0x00060000 |
int | PERSISTENT_ALL_CACHES | Used to indicate that all drawing caches should be kept in memory. | 3 | 0x00000003 |
int | PERSISTENT_ANIMATION_CACHE | Used to indicate that the animation drawing cache should be kept in memory. | 1 | 0x00000001 |
int | PERSISTENT_NO_CACHE | Used to indicate that no drawing cache should be kept in memory. | 0 | 0x00000000 |
int | PERSISTENT_SCROLLING_CACHE | Used to indicate that the scrolling drawing cache should be kept in memory. | 2 | 0x00000002 |
protected | ArrayList<View> | mDisappearingChildren | Views which have been hidden or removed which need to be animated on their way out | ||
protected | int | mGroupFlags | |||
protected | ViewGroup.OnHierarchyChangeListener | mOnHierarchyChangeListener | Listener used to propagate events indicating when children are added and/or removed from a view group. | ||
protected | int | mPersistentDrawingCache | Indicates which types of drawing caches are to be kept in memory. |
ViewGroup(Context context) | ||||||
ViewGroup(Context context, AttributeSet attrs) | ||||||
ViewGroup(Context context, AttributeSet attrs, int defStyle) |
void | addFocusables(ArrayList<View> views, int direction) | |||||
Add any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. | ||||||
boolean | addStatesFromChildren() | |||||
Returns whether this ViewGroup's drawable states also include its children's drawable states. | ||||||
void | addTouchables(ArrayList<View> views) | |||||
Add any touchable views that are descendants of this view (possibly including this view if it is touchable itself) to views. | ||||||
void | addView(View child, int index) | |||||
Adds a child view. | ||||||
void | addView(View child, int width, int height) | |||||
Adds a child view with this ViewGroup's default layout parameters and the specified width and height. | ||||||
void | addView(View child, ViewGroup.LayoutParams params) | |||||
Adds a child view with the specified layout parameters. | ||||||
void | addView(View child, int index, ViewGroup.LayoutParams params) | |||||
Adds a child view with the specified layout parameters. | ||||||
void | addView(View child) | |||||
Adds a child view. | ||||||
void | bringChildToFront(View child) | |||||
Change the z order of the child so it's on top of all other children | ||||||
void | childDrawableStateChanged(View child) | |||||
If {link #addStatesFromChildren} is true, refreshes this group's drawable state (to include the states from its children). | ||||||
void | clearChildFocus(View child) | |||||
Called when a child of this parent is giving up focus | ||||||
void | clearDisappearingChildren() | |||||
Removes any pending animations for views that have been removed. | ||||||
void | clearFocus() | |||||
Called when this view wants to give up focus. | ||||||
boolean | dispatchKeyEvent(KeyEvent event) | |||||
Dispatch a key event to the next view on the focus path. | ||||||
void | dispatchSetSelected(boolean selected) | |||||
Dispatch setSelected to all of this View's children. | ||||||
boolean | dispatchTouchEvent(MotionEvent ev) | |||||
Pass the touch screen motion event down to the target view, or this view if it is the target. | ||||||
boolean | dispatchTrackballEvent(MotionEvent event) | |||||
Pass a trackball motion event down to the focused view. | ||||||
boolean | dispatchUnhandledMove(View focused, int direction) | |||||
This method is the last chance for the focused view and its ancestors to respond to an arrow key. | ||||||
void | dispatchWindowFocusChanged(boolean hasFocus) | |||||
Called when the window containing this view gains or loses window focus. | ||||||
void | dispatchWindowVisibilityChanged(int visibility) | |||||
Dispatch a window visibility change down the view hierarchy. | ||||||
View | findFocus() | |||||
Find the view in the hierarchy rooted at this view that currently has focus. | ||||||
View | focusSearch(View focused, int direction) | |||||
Find the nearest view in the specified direction that wants to take focus. | ||||||
void | focusableViewAvailable(View v) | |||||
Tells the parent that a new focusable view has become available. | ||||||
boolean | gatherTransparentRegion(Region region) | |||||
This is used by the RootView to perform an optimization when the view hierarchy contains one or several SurfaceView. | ||||||
ViewGroup.LayoutParams | generateLayoutParams(AttributeSet attrs) | |||||
Returns a new set of layout parameters based on the supplied attributes set. | ||||||
View | getChildAt(int index) | |||||
Returns the view at the specified position in the group. | ||||||
int | getChildCount() | |||||
Returns the number of children in the group. | ||||||
static | int | getChildMeasureSpec(int spec, int padding, int childDimension) | ||||
Does the hard part of measureChildren: figuring out the MeasureSpec to pass to a particular child. | ||||||
boolean | getChildVisibleRect(View child, Rect r, Point offset) | |||||
int | getDescendantFocusability() | |||||
Gets the descendant focusability of this view group. | ||||||
View | getFocusedChild() | |||||
Returns the focused child of this view, if any. | ||||||
LayoutAnimationController | getLayoutAnimation() | |||||
Returns the layout animation controller used to animate the group's children. | ||||||
Animation.AnimationListener | getLayoutAnimationListener() | |||||
Returns the animation listener to which layout animation events are sent. | ||||||
int | getPersistentDrawingCache() | |||||
Returns an integer indicating what types of drawing caches are kept in memory. | ||||||
boolean | hasFocus() | |||||
Returns true if this view has or contains focus | ||||||
boolean | hasFocusable() | |||||
Returns true if this view is focusable or if it contains a reachable View for which hasFocusable() returns true. | ||||||
int | indexOfChild(View child) | |||||
Returns the position in the group of the specified child view. | ||||||
final | void | invalidateChild(View child, Rect dirty) | ||||
Don't call or override this method. | ||||||
ViewParent | invalidateChildInParent(int[] location, Rect dirty) | |||||
Don't call or override this method. | ||||||
boolean | isAlwaysDrawnWithCacheEnabled() | |||||
Indicates whether this ViewGroup will always try to draw its children using their drawing cache. | ||||||
boolean | isAnimationCacheEnabled() | |||||
Indicates whether the children's drawing cache is used during a layout animation. | ||||||
final | void | offsetDescendantRectToMyCoords(View descendant, Rect rect) | ||||
Offset a rectangle that is in a descendant's coordinate space into our coordinate space. | ||||||
final | void | offsetRectIntoDescendantCoords(View descendant, Rect rect) | ||||
Offset a rectangle that is in our coordinate space into an ancestor's coordinate space. | ||||||
boolean | onInterceptTouchEvent(MotionEvent ev) | |||||
Implement this method to intercept all touch screen motion events. | ||||||
void | recomputeViewAttributes(View child) | |||||
Tell view hierarchy that the global view attributes need to be re-evaluated. | ||||||
void | removeAllViews() | |||||
Call this method to remove all child views from the ViewGroup. | ||||||
void | removeAllViewsInLayout() | |||||
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. | ||||||
void | removeView(View view) | |||||
void | removeViewAt(int index) | |||||
Removes the view at the specified position in the group. | ||||||
void | removeViewInLayout(View view) | |||||
Removes a view during layout. | ||||||
void | removeViews(int start, int count) | |||||
Removes the specified range of views from the group. | ||||||
void | removeViewsInLayout(int start, int count) | |||||
Removes a range of views during layout. | ||||||
void | requestChildFocus(View child, View focused) | |||||
Called when a child of this parent wants focus | ||||||
boolean | requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) | |||||
Called when a child of this group wants a particular rectangle to be positioned onto the screen. | ||||||
void | requestDisallowInterceptTouchEvent(boolean disallowIntercept) | |||||
Called when a child does not want this parent and its ancestors to intercept touch events with onInterceptTouchEvent(MotionEvent). | ||||||
boolean | requestFocus(int direction, Rect previouslyFocusedRect) | |||||
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(). | ||||||
void | requestTransparentRegion(View child) | |||||
Called when a child wants the view hierarchy to gather and report transparent regions to the window compositor. | ||||||
void | scheduleLayoutAnimation() | |||||
Schedules the layout animation to be played after the next layout pass of this view group. | ||||||
void | setAddStatesFromChildren(boolean addsStates) | |||||
Sets whether this ViewGroup's drawable states also include its children's drawable states. | ||||||
void | setAlwaysDrawnWithCacheEnabled(boolean always) | |||||
Indicates whether this ViewGroup will always try to draw its children using their drawing cache. | ||||||
void | setAnimationCacheEnabled(boolean enabled) | |||||
Enables or disables the children's drawing cache during a layout animation. | ||||||
void | setClipChildren(boolean clipChildren) | |||||
By default, children are clipped to their bounds before drawing. | ||||||
void | setClipToPadding(boolean clipToPadding) | |||||
By default, children are clipped to the padding of the ViewGroup. | ||||||
void | setDescendantFocusability(int focusability) | |||||
Set the descendant focusability of this view group. | ||||||
void | setLayoutAnimation(LayoutAnimationController controller) | |||||
Sets the layout animation controller used to animate the group's children after the first layout. | ||||||
void | setLayoutAnimationListener(Animation.AnimationListener animationListener) | |||||
Specifies the animation listener to which layout animation events must be sent. | ||||||
void | setOnHierarchyChangeListener(ViewGroup.OnHierarchyChangeListener listener) | |||||
Register a callback to be invoked when a child is added to or removed from this view. | ||||||
void | setPadding(int left, int top, int right, int bottom) | |||||
Sets the padding. | ||||||
void | setPersistentDrawingCache(int drawingCacheToKeep) | |||||
Indicates what types of drawing caches should be kept in memory after they have been created. | ||||||
boolean | showContextMenuForChild(View originalView) | |||||
Bring up a context menu for the specified view or its ancestors. | ||||||
void | startLayoutAnimation() | |||||
Runs the layout animation. | ||||||
void | updateViewLayout(View view, ViewGroup.LayoutParams params) | |||||
boolean | addViewInLayout(View child, int index, ViewGroup.LayoutParams params) | |||||
Adds a view during layout. | ||||||
boolean | addViewInLayout(View child, int index, ViewGroup.LayoutParams params, boolean preventRequestLayout) | |||||
Adds a view during layout. | ||||||
void | attachLayoutAnimationParameters(View child, ViewGroup.LayoutParams params, int index, int count) | |||||
Subclasses should override this method to set layout animation parameters on the supplied child. | ||||||
void | attachViewToParent(View child, int index, ViewGroup.LayoutParams params) | |||||
Attaches a view to this view group. | ||||||
boolean | canAnimate() | |||||
Indicates whether the view group has the ability to animate its children after the first layout. | ||||||
boolean | checkLayoutParams(ViewGroup.LayoutParams p) | |||||
void | cleanupLayoutState(View child) | |||||
Prevents the specified child to be laid out during the next layout pass. | ||||||
void | debug(int depth) | |||||
Prints information about this view in the log output, with the tag VIEW_LOG_TAG. | ||||||
void | detachAllViewsFromParent() | |||||
Detaches all views from theparent. | ||||||
void | detachViewFromParent(View child) | |||||
Detaches a view from its parent. | ||||||
void | detachViewFromParent(int index) | |||||
Detaches a view from its parent. | ||||||
void | detachViewsFromParent(int start, int count) | |||||
Detaches a range of view from their parent. | ||||||
void | dispatchDraw(Canvas canvas) | |||||
Called by draw to draw the child views. | ||||||
void | dispatchFreezeSelfOnly(SparseArray<Parcelable> container) | |||||
Perform dispatching of a freeze() to only this view, not to its children. | ||||||
void | dispatchRestoreInstanceState(SparseArray<Parcelable> container) | |||||
Called by restoreHierarchyState(SparseArray |
||||||
void | dispatchSaveInstanceState(SparseArray<Parcelable> container) | |||||
Called by saveHierarchyState(SparseArray |
||||||
void | dispatchSetPressed(boolean pressed) | |||||
Dispatch setPressed to all of this View's children. | ||||||
void | dispatchThawSelfOnly(SparseArray<Parcelable> container) | |||||
Perform dispatching of a thaw() to only this view, not to its children. | ||||||
boolean | drawChild(Canvas canvas, View child, long drawingTime) | |||||
Draw one child of this View Group. | ||||||
void | drawableStateChanged() | |||||
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown. | ||||||
boolean | fitSystemWindows(Rect insets) | |||||
Apply the insets for system windows to this view, if the FITS_SYSTEM_WINDOWS flag is set | ||||||
ViewGroup.LayoutParams | generateDefaultLayoutParams() | |||||
Returns a set of default layout parameters. | ||||||
ViewGroup.LayoutParams | generateLayoutParams(ViewGroup.LayoutParams p) | |||||
Returns a safe set of layout parameters based on the supplied layout params. | ||||||
int | getChildDrawingOrder(int childCount, int i) | |||||
Returns the index of the child to draw for this iteration. | ||||||
boolean | getChildStaticTransformation(View child, Transformation t) | |||||
boolean | isChildrenDrawnWithCacheEnabled() | |||||
Indicates whether the ViewGroup is currently drawing its children using their drawing cache. | ||||||
void | measureChild(View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec) | |||||
Ask one of the children of this view to measure itself, taking into account both the MeasureSpec requirements for this view and its padding. | ||||||
void | measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) | |||||
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. | ||||||
void | measureChildren(int widthMeasureSpec, int heightMeasureSpec) | |||||
Ask all of the children of this view to measure themselves, taking into account both the MeasureSpec requirements for this view and its padding. | ||||||
void | onAnimationEnd() | |||||
Invoked by a parent ViewGroup to notify the end of the animation currently associated with this view. | ||||||
void | onAnimationStart() | |||||
Invoked by a parent ViewGroup to notify the start of the animation currently associated with this view. | ||||||
int[] | onCreateDrawableState(int extraSpace) | |||||
Generate the new Drawable state for this view. | ||||||
abstract | void | onLayout(boolean changed, int l, int t, int r, int b) | ||||
Called from layout when this view should assign a size and position to each of its children. | ||||||
boolean | onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) | |||||
Look for a descendant to call requestFocus() on. | ||||||
void | removeDetachedView(View child, boolean animate) | |||||
Finishes the removal of a detached view. | ||||||
void | setChildrenDrawingCacheEnabled(boolean enabled) | |||||
Enables or disables the drawing cache for each child of this view group. | ||||||
void | setChildrenDrawnWithCacheEnabled(boolean enabled) | |||||
Tells the ViewGroup to draw its children using their drawing cache. |
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.
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.
views | Focusable views found so far |
---|---|
direction | The direction of the focus |
views | Touchable views found so far |
---|
child | the child view to add |
---|---|
index | the position at which to add the child |
child | the child view to add |
---|
child | the child view to add |
---|---|
params | the layout parameters to set on the child |
child | the child view to add |
---|---|
index | the position at which to add the child |
params | the layout parameters to set on the child |
child | the child view to add |
---|
event | The key event to be dispatched. |
---|
selected | The new selected state |
---|
ev | The motion event to be dispatched. |
---|
event | The motion event to be dispatched. |
---|
focused | The currently focused view. |
---|---|
direction | The direction focus wants to move. One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
hasFocus | True if the window containing this view now has focus, false otherwise. |
---|
visibility | The new visibility of the window. |
---|
focused | The view that currently has focus |
---|---|
direction | One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT, or 0 for not applicable. |
region | The transparent region for this ViewRoot (window). |
---|
attrs | the attributes to build the layout parameters from |
---|
index | the position at which to get the view from |
---|
spec | The requirements for this view |
---|---|
padding | The padding of this view for the current dimension and margins, if applicable |
childDimension | How big the child wants to be in the current dimension |
child | the view for which to get the position |
---|
descendant | A descendant of this view |
---|---|
rect | A rectangle defined in descendant's coordinate space. |
descendant | A descendant of this view |
---|---|
rect | A rectangle defined in descendant's coordinate space. |
Using this function takes some care, as it has a fairly complicated interaction with View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:
ev | The motion event being dispatched down the hierarchy. |
---|
index | the position in the group of the view to remove |
---|
view | the view to remove from the group |
---|
start | the first position in the group of the range of views to remove |
---|---|
count | the number of views to remove |
start | the index of the first view to remove from the group |
---|---|
count | the number of views to remove from the group |
ViewGroups overriding this should uphold the contract:
child | The direct child making the request. |
---|---|
rectangle | The rectangle in the child's coordinates the child wishes to be on the screen. |
immediate | True to forbid animated or delayed scrolling, false otherwise |
This parent should pass this call onto its parents. This parent must obey this request for the duration of the touch (that is, only clear the flag after this parent has received an up or a cancel.
direction | One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
---|---|
previouslyFocusedRect | The rectangle (in this View's coordinate system) to give a finer grained hint about where focus is coming from. May be null if there is no hint. |
always | true to always draw with the drawing cache, false otherwise |
---|
enabled | true to enable the animation cache, false otherwise |
---|
clipChildren | true to clip children to their bounds, false otherwise |
---|
clipToPadding | true to clip children to the padding of the group, false otherwise |
---|
focusability | one of FOCUS_BEFORE_DESCENDANTS, FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS. |
---|
controller | the animation controller |
---|
animationListener | the layout animation listener |
---|
listener | the callback to invoke on hierarchy change |
---|
left | the left padding in pixels |
---|---|
top | the top padding in pixels |
right | the right padding in pixels |
bottom | the bottom padding in pixels |
drawingCacheToKeep | one or a combination of PERSISTENT_NO_CACHE, PERSISTENT_ANIMATION_CACHE, PERSISTENT_SCROLLING_CACHE and PERSISTENT_ALL_CACHES |
---|
In most cases, a subclass does not need to override this. However, if the subclass is added directly to the window manager (for example, addView(View, android.view.ViewGroup.LayoutParams)) then it should override this and show the context menu.
child | the view to add to the group |
---|---|
index | the index at which the child must be added |
params | the layout parameters to associate with the child |
child | the view to add to the group |
---|---|
index | the index at which the child must be added |
params | the layout parameters to associate with the child |
preventRequestLayout | if true, calling this method will not trigger a layout request on child |
child | the child to associate with animation parameters |
---|---|
params | the child's layout parameters which hold the animation parameters |
index | the index of the child in the view group |
count | the number of children in the view group |
child | the child to attach |
---|---|
index | the index at which the child should be attached |
params | the layout parameters of the child |
child | the child on which to perform the cleanup |
---|
depth
.
depth | the indentation level |
---|
child | the child to detach |
---|
index | the index of the child to detach |
---|
start | the first index of the childrend range to detach |
---|---|
count | the number of children to detach |
canvas | the canvas on which to draw the view |
---|
container | the container |
---|
container | The SparseArray which holds previously saved state. |
---|
container | The SparseArray in which to save the view's state. |
---|
pressed | The new pressed state |
---|
container | the container |
---|
canvas | The canvas on which to draw the child |
---|---|
child | Who to draw |
drawingTime | The time at which draw is occuring |
Be sure to call through to the superclass when overriding this function.
insets | Insets for system windows |
---|
p | The layout parameters to convert into a suitable set of layout parameters for this ViewGroup. |
---|
NOTE: In order for this method to be called, the FLAG_USE_CHILD_DRAWING_ORDER must be set.
i | The current iteration. |
---|
child | The child to measure |
---|---|
parentWidthMeasureSpec | The width requirements for this view |
parentHeightMeasureSpec | The height requirements for this view |
child | The child to measure |
---|---|
parentWidthMeasureSpec | The width requirements for this view |
widthUsed | Extra space that has been used up by the parent horizontally (possibly by other children of the parent) |
parentHeightMeasureSpec | The height requirements for this view |
heightUsed | Extra space that has been used up by the parent vertically (possibly by other children of the parent) |
widthMeasureSpec | The width requirements for this view |
---|---|
heightMeasureSpec | The height requirements for this view |
extraSpace | if non-zero, this is the number of extra entries you would like in the returned array in which you can place your own states. |
---|
changed | This is a new size or position for this view |
---|---|
l | Left position, relative to parent |
t | Top position, relative to parent |
r | Right position, relative to parent |
b | Bottom position, relative to parent |
direction | One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
---|---|
previouslyFocusedRect | The rectangle (in this View's coordinate system) to give a finer grained hint about where focus is coming from. May be null if there is no hint. |
child | the child to be definitely removed from the view hierarchy |
---|---|
animate | if true and the view has an animation, the view is placed in the disappearing views list, otherwise, it is detached from the window |
enabled | true to enable the cache, false to dispose of it |
---|
enabled | true if children should be drawn with their cache, false otherwise |
---|
Copyright 2007 Google Inc. | Build 0.9_r1-98467 - 14 Aug 2008 18:48 |