English | Site Directory

Android - An Open Handset Alliance Project

android.view
public abstract class

android.view.ViewGroup

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.

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. 
Known Direct Subclasses
Known Indirect Subclasses

Summary

XML Attributes

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. 
XML Attributes inherited from class android.view.View

Constants

      Value  
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  PERSISTENT_ALL_CACHES  Used to indicate that all drawing caches should be kept in memory.  0x00000003 
int  PERSISTENT_ANIMATION_CACHE  Used to indicate that the animation drawing cache should be kept in memory.  0x00000001 
int  PERSISTENT_NO_CACHE  Used to indicate that no drawing cache should be kept in memory.  0x00000000 
int  PERSISTENT_SCROLLING_CACHE  Used to indicate that the scrolling drawing cache should be kept in memory.  0x00000002 
Constants inherited from class android.view.View

Fields

protected      ArrayList  mDisappearingChildren  Views which have been hidden or removed which need to be animated on their way out  
protected      int  mGroupFlags   
protected      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. 
Fields inherited from class android.view.View

Public Constructors

          ViewGroup(Context context)
          ViewGroup(Context context, AttributeSet attrs, Map inflateParams)
          ViewGroup(Context context, AttributeSet attrs, Map inflateParams, int defStyle)

Public Methods

        void  addView(View child, int index)
Adds a child view that already has layout parameters set on it.
        void  addView(View child, int index, LayoutParams params)
Adds a child view with the specified layout parameters.
        void  addView(View child, LayoutParams params)
Adds a child view with the specified layout parameters.
        void  addView(View child)
Adds a child view that already has layout parameters set on it.
        boolean  addsStatesFromChildren()
Returns whether this ViewGroup's drawable states also include its children's drawable states.
        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 #addsStatesFromChildren} 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.
        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 v, 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.
        LayoutParams  generateLayoutParams(AttributeSet attrs)
        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)
        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.
        AnimationListener  getLayoutAnimationListener()
Returns the animation listener to which layout animation events are sent.
        int  getPeristentDrawingCache()
Returns an integer indicating what types of drawing caches are kept in memory.
        boolean  hasFocus()
Returns true if this view has or contains focus
        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.
    final    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.
        boolean  isKeepAnimations()
Indicates whether animations set on this view group's children are kept after they're over or not.
    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  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  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.
        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. This implements the focus type logic (getFocusType()), respecting this group's preference for NORMAL_FOCUS or WEAK_FOCUS.
        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  setAddsStatesFromChildren(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  setKeepAnimations(boolean keepAnimations)
Indicates whether the view group keeps its children animations after they are over or not.
        void  setLayoutAnimation(LayoutAnimationController controller)
Sets the layout animation controller used to animate the group's children after the first layout.
        void  setLayoutAnimationListener(AnimationListener animationListener)
Specifies the animation listener to which layout animation events must be sent.
        void  setOnHierarchyChangeListener(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.
        void  setSelected(boolean selected)
Changes the selection state of this view.
        boolean  showContextMenuForChild(View v)
Bring up a context menu for the specified view or its ancestors
        void  startLayoutAnimation()
Runs the layout animation.
        void  updateViewLayout(View view, LayoutParams params)

Protected Methods

        boolean  addViewInLayout(View child, int index, LayoutParams params)
Adds a view during layout.
        boolean  addViewInLayout(View child, int index, LayoutParams params, boolean preventRequestLayout)
Adds a view during layout.
        void  attachLayoutAnimationParameters(View child, 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, 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(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  dispatchDraw(Canvas canvas)
Called by draw to draw the child views.
        void  dispatchFreeze(SparseArray container)
Called by freeze(SparseArray) to store the icicles for this view and its children.
        void  dispatchFreezeSelfOnly(SparseArray container)
Perform dispatching of a freeze() to only this view, not to its children.
        void  dispatchThaw(SparseArray container)
Called by thaw(SparseArray) to retrieve the icicles for this view and its children.
        void  dispatchThawSelfOnly(SparseArray container)
Perform dispatching of a thaw() to only this view, not to its children.
        boolean  getChildStaticTransformation(View child, Transformation t)
        boolean  isChildrenDrawnWithCacheEnabled()
Indicates whether the ViewGroup is currently drawing its children using their drawing cache.
        void  measureChild(Vi