to top
Android APIs
Since: API Level 1
public interface

ViewParent

android.view.ViewParent
Known Indirect Subclasses

Class Overview

Defines the responsibilities for a class that will be a parent of a View. This is the API that a view sees when it wants to interact with its parent.

Summary

Public Methods
abstract void bringChildToFront(View child)
Change the z order of the child so it's on top of all other children
abstract void childDrawableStateChanged(View child)
This method is called on the parent when a child's drawable state has changed.
abstract void clearChildFocus(View child)
Called when a child of this parent is giving up focus
abstract void createContextMenu(ContextMenu menu)
Have the parent populate the specified context menu if it has anything to add (and then recurse on its parent).
abstract View focusSearch(View v, int direction)
Find the nearest view in the specified direction that wants to take focus
abstract void focusableViewAvailable(View v)
Tells the parent that a new focusable view has become available.
abstract boolean getChildVisibleRect(View child, Rect r, Point offset)
Compute the visible part of a rectangular region defined in terms of a child view's coordinates.
abstract ViewParent getParent()
Returns the parent if it exists, or null.
abstract ViewParent getParentForAccessibility()
Gets the parent of a given View for accessibility.
abstract void invalidateChild(View child, Rect r)
All or part of a child is dirty and needs to be redrawn.
abstract ViewParent invalidateChildInParent(int[] location, Rect r)
All or part of a child is dirty and needs to be redrawn.
abstract boolean isLayoutRequested()
Indicates whether layout was requested on this view parent.
abstract void recomputeViewAttributes(View child)
Tell view hierarchy that the global view attributes need to be re-evaluated.
abstract void requestChildFocus(View child, View focused)
Called when a child of this parent wants focus
abstract 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.
abstract void requestDisallowInterceptTouchEvent(boolean disallowIntercept)
Called when a child does not want this parent and its ancestors to intercept touch events with onInterceptTouchEvent(MotionEvent).
abstract void requestFitSystemWindows()
Ask that a new dispatch of View.fitSystemWindows(Rect) be performed.
abstract void requestLayout()
Called when something has changed which has invalidated the layout of a child of this view parent.
abstract boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event)
Called by a child to request from its parent to send an AccessibilityEvent.
abstract void requestTransparentRegion(View child)
Called when a child wants the view hierarchy to gather and report transparent regions to the window compositor.
abstract boolean showContextMenuForChild(View originalView)
Bring up a context menu for the specified view or its ancestors.
abstract ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback)
Start an action mode for the specified view.

Public Methods

public abstract void bringChildToFront (View child)

Since: API Level 1

Change the z order of the child so it's on top of all other children

public abstract void childDrawableStateChanged (View child)

Since: API Level 1

This method is called on the parent when a child's drawable state has changed.

Parameters
child The child whose drawable state has changed.

public abstract void clearChildFocus (View child)

Since: API Level 1

Called when a child of this parent is giving up focus

Parameters
child The view that is giving up focus

public abstract void createContextMenu (ContextMenu menu)

Since: API Level 1

Have the parent populate the specified context menu if it has anything to add (and then recurse on its parent).

Parameters
menu The menu to populate

public abstract View focusSearch (View v, int direction)

Since: API Level 1

Find the nearest view in the specified direction that wants to take focus

Parameters
v The view that currently has focus
direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT

public abstract void focusableViewAvailable (View v)

Since: API Level 1

Tells the parent that a new focusable view has become available. This is to handle transitions from the case where there are no focusable views to the case where the first focusable view appears.

Parameters
v The view that has become newly focusable

public abstract boolean getChildVisibleRect (View child, Rect r, Point offset)

Since: API Level 1

Compute the visible part of a rectangular region defined in terms of a child view's coordinates.

Returns the clipped visible part of the rectangle r, defined in the child's local coordinate system. r is modified by this method to contain the result, expressed in the global (root) coordinate system.

The resulting rectangle is always axis aligned. If a rotation is applied to a node in the View hierarchy, the result is the axis-aligned bounding box of the visible rectangle.

Parameters
child A child View, whose rectangular visible region we want to compute
r The input rectangle, defined in the child coordinate system. Will be overwritten to contain the resulting visible rectangle, expressed in global (root) coordinates
offset The input coordinates of a point, defined in the child coordinate system. As with the r parameter, this will be overwritten to contain the global (root) coordinates of that point. A null value is valid (in case you are not interested in this result)
Returns
  • true if the resulting rectangle is not empty, false otherwise

public abstract ViewParent getParent ()

Since: API Level 1

Returns the parent if it exists, or null.

Returns
  • a ViewParent or null if this ViewParent does not have a parent

public abstract ViewParent getParentForAccessibility ()

Since: API Level 16

Gets the parent of a given View for accessibility. Since some Views are not exposed to the accessibility layer the parent for accessibility is not necessarily the direct parent of the View, rather it is a predecessor.

Returns
  • The parent or null if no such is found.

public abstract void invalidateChild (View child, Rect r)

Since: API Level 1

All or part of a child is dirty and needs to be redrawn.

Parameters
child The child which is dirty
r The area within the child that is invalid

public abstract ViewParent invalidateChildInParent (int[] location, Rect r)

Since: API Level 1

All or part of a child is dirty and needs to be redrawn.

The location array is an array of two int values which respectively define the left and the top position of the dirty child.

This method must return the parent of this ViewParent if the specified rectangle must be invalidated in the parent. If the specified rectangle does not require invalidation in the parent or if the parent does not exist, this method must return null.

When this method returns a non-null value, the location array must have been updated with the left and top coordinates of this ViewParent.

Parameters
location An array of 2 ints containing the left and top coordinates of the child to invalidate
r The area within the child that is invalid
Returns
  • the parent of this ViewParent or null

public abstract boolean isLayoutRequested ()

Since: API Level 1

Indicates whether layout was requested on this view parent.

Returns
  • true if layout was requested, false otherwise

public abstract void recomputeViewAttributes (View child)

Since: API Level 1

Tell view hierarchy that the global view attributes need to be re-evaluated.

Parameters
child View whose attributes have changed.

public abstract void requestChildFocus (View child, View focused)

Since: API Level 1

Called when a child of this parent wants focus

Parameters
child The child of this ViewParent that wants focus. This view will contain the focused view. It is not necessarily the view that actually has focus.
focused The view that is a descendant of child that actually has focus

public abstract boolean requestChildRectangleOnScreen (View child, Rect rectangle, boolean immediate)

Since: API Level 3

Called when a child of this group wants a particular rectangle to be positioned onto the screen. ViewGroups overriding this can trust that:

  • child will be a direct child of this group
  • rectangle will be in the child's coordinates

ViewGroups overriding this should uphold the contract:

  • nothing will change if the rectangle is already visible
  • the view port will be scrolled only just enough to make the rectangle visible
Parameters
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
Returns
  • Whether the group scrolled to handle the operation

public abstract void requestDisallowInterceptTouchEvent (boolean disallowIntercept)

Since: API Level 1

Called when a child does not want this parent and its ancestors to intercept touch events with onInterceptTouchEvent(MotionEvent).

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.

Parameters
disallowIntercept True if the child does not want the parent to intercept touch events.

public abstract void requestFitSystemWindows ()

Since: API Level 16

Ask that a new dispatch of View.fitSystemWindows(Rect) be performed.

public abstract void requestLayout ()

Since: API Level 1

Called when something has changed which has invalidated the layout of a child of this view parent. This will schedule a layout pass of the view tree.

public abstract boolean requestSendAccessibilityEvent (View child, AccessibilityEvent event)

Since: API Level 14

Called by a child to request from its parent to send an AccessibilityEvent. The child has already populated a record for itself in the event and is delegating to its parent to send the event. The parent can optionally add a record for itself.

Note: An accessibility event is fired by an individual view which populates the event with a record for its state and requests from its parent to perform the sending. The parent can optionally add a record for itself before dispatching the request to its parent. A parent can also choose not to respect the request for sending the event. The accessibility event is sent by the topmost view in the view tree.

Parameters
child The child which requests sending the event.
event The event to be sent.
Returns
  • True if the event was sent.

public abstract void requestTransparentRegion (View child)

Since: API Level 1

Called when a child wants the view hierarchy to gather and report transparent regions to the window compositor. Views that "punch" holes in the view hierarchy, such as SurfaceView can use this API to improve performance of the system. When no such a view is present in the hierarchy, this optimization in unnecessary and might slightly reduce the view hierarchy performance.

Parameters
child the view requesting the transparent region computation

public abstract boolean showContextMenuForChild (View originalView)

Since: API Level 1

Bring up a context menu for the specified view or its ancestors.

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.

Parameters
originalView The source view where the context menu was first invoked
Returns
  • true if a context menu was displayed

public abstract ActionMode startActionModeForChild (View originalView, ActionMode.Callback callback)

Since: API Level 11

Start an action mode for the specified view.

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 start the action mode.

Parameters
originalView The source view where the action mode was first invoked
callback The callback that will handle lifecycle events for the action mode
Returns
  • The new action mode if it was started, null otherwise