Class ViewGroup

java.lang.Object
icyllis.modernui.view.View
icyllis.modernui.view.ViewGroup
All Implemented Interfaces:
Drawable.Callback, ViewManager, ViewParent
Direct Known Subclasses:
AbsoluteLayout, AdapterView, CoordinatorLayout, FrameLayout, GridLayout, LinearLayout, RelativeLayout, ViewPager, WindowGroup

@UiThread public abstract class ViewGroup extends View implements ViewParent, ViewManager

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.

  • Field Details

    • FOCUS_BEFORE_DESCENDANTS

      public static final int FOCUS_BEFORE_DESCENDANTS
      This view will get focus before any of its descendants.
      See Also:
    • FOCUS_AFTER_DESCENDANTS

      public static final int FOCUS_AFTER_DESCENDANTS
      This view will get focus only if none of its descendants want it.
      See Also:
    • FOCUS_BLOCK_DESCENDANTS

      public static final int FOCUS_BLOCK_DESCENDANTS
      This view will block any of its descendants from getting focus, even if they are focusable.
      See Also:
    • FLAG_DISALLOW_INTERCEPT

      @Internal protected static final int FLAG_DISALLOW_INTERCEPT
      When set, this ViewGroup should not intercept touch events.
      See Also:
    • CLIP_TO_PADDING_MASK

      protected static final 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.
      See Also:
  • Constructor Details

    • ViewGroup

      public ViewGroup(Context context)
  • Method Details

    • dispatchDraw

      protected void dispatchDraw(@NonNull Canvas canvas)
      Description copied from class: View
      Draw the child views.
      Overrides:
      dispatchDraw in class View
      Parameters:
      canvas - the canvas to draw content
    • drawChild

      protected void drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime)
      Draw one child of this View Group. This method is responsible for getting the canvas in the right state. This includes clipping, translating so that the child's scrolled origin is at 0, 0, and applying any animation transformations.
      Parameters:
      canvas - The canvas on which to draw the child
      child - Who to draw
      drawingTime - The time at which draw is occurring
    • layout

      public final void layout(int l, int t, int r, int b)
      Description copied from class: View
      Specifies the rectangle area of this view and all its descendants.

      Derived classes should NOT override this method for any reason. Derived classes with children should override View.onLayout(boolean, int, int, int, int). In that method, they should call layout() on each of their children.

      Overrides:
      layout in class View
      Parameters:
      l - left position, relative to parent
      t - top position, relative to parent
      r - right position, relative to parent
      b - bottom position, relative to parent
    • onLayout

      protected abstract void onLayout(boolean changed, int left, int top, int right, int bottom)
      Description copied from class: View
      Called from View.layout(int, int, int, int) when this view should assign a size and position to each of its children.

      Derived classes with children should override this method and call layout on each of their children.

      Overrides:
      onLayout in class View
      Parameters:
      changed - This is a new size or position for this view
      left - Left position, relative to parent
      top - Top position, relative to parent
      right - Right position, relative to parent
      bottom - Bottom position, relative to parent
    • dispatchHoverEvent

      protected boolean dispatchHoverEvent(@NonNull MotionEvent event)
      Description copied from class: View
      Dispatch a hover event.

      Do not call this method directly. Call View.dispatchGenericMotionEvent(MotionEvent) instead.

      Overrides:
      dispatchHoverEvent in class View
      Parameters:
      event - The motion event to be dispatched.
      Returns:
      True if the event was handled by the view, false otherwise.
    • onInterceptHoverEvent

      public boolean onInterceptHoverEvent(@NonNull MotionEvent event)
      Implement this method to intercept hover events before they are handled by child views.

      This method is called before dispatching a hover event to a child of the view group or to the view group's own View.onHoverEvent(icyllis.modernui.view.MotionEvent) to allow the view group a chance to intercept the hover event. This method can also be used to watch all pointer motions that occur within the bounds of the view group even when the pointer is hovering over a child of the view group rather than over the view group itself.

      The view group can prevent its children from receiving hover events by implementing this method and returning true to indicate that it would like to intercept hover events. The view group must continuously return true from this method for as long as it wishes to continue intercepting hover events from its children.

      Interception preserves the invariant that at most one view can be hovered at a time by transferring hover focus from the currently hovered child to the view group or vice-versa as needed.

      If this method returns true and a child is already hovered, then the child view will first receive a hover exit event and then the view group itself will receive a hover enter event in View.onHoverEvent(icyllis.modernui.view.MotionEvent). Likewise, if this method had previously returned true to intercept hover events and instead returns false while the pointer is hovering within the bounds of one of a child, then the view group will first receive a hover exit event in View.onHoverEvent(icyllis.modernui.view.MotionEvent) and then the hovered child will receive a hover enter event.

      The default implementation handles mouse hover on the scroll bars.

      Parameters:
      event - The motion event that describes the hover.
      Returns:
      True if the view group would like to intercept the hover event and prevent its children from receiving it.
    • dispatchGenericPointerEvent

      protected boolean dispatchGenericPointerEvent(@NonNull MotionEvent event)
      Description copied from class: View
      Dispatch a generic motion event to the view under the first pointer.

      Do not call this method directly. Call View.dispatchGenericMotionEvent(MotionEvent) instead.

      Overrides:
      dispatchGenericPointerEvent in class View
      Parameters:
      event - The motion event to be dispatched.
      Returns:
      True if the event was handled by the view, false otherwise.
    • dispatchTouchEvent

      public boolean dispatchTouchEvent(@NonNull MotionEvent ev)
      Description copied from class: View
      Pass the touch screen motion event down to the target view, or this view if it is the target.
      Overrides:
      dispatchTouchEvent in class View
      Parameters:
      ev - The motion event to be dispatched.
      Returns:
      true if the event was handled by the view, false otherwise
    • isTransitionGroup

      public boolean isTransitionGroup()
      Returns true if this ViewGroup should be considered as a single entity for removal when executing an Activity transition. If this is false, child elements will move individually during the transition.
      Returns:
      True if the ViewGroup should be acted on together during an Activity transition. The default value is true when there is a non-null background or if View.getTransitionName() is not null and false otherwise.
    • setTransitionGroup

      public void setTransitionGroup(boolean isTransitionGroup)
      Changes whether or not this ViewGroup should be treated as a single entity during Activity Transitions.
      Parameters:
      isTransitionGroup - Whether or not the ViewGroup should be treated as a unit in Activity transitions. If false, the ViewGroup won't transition, only its children. If true, the entire ViewGroup will transition together.
    • requestDisallowInterceptTouchEvent

      public void requestDisallowInterceptTouchEvent(boolean disallowIntercept)
      Description copied from interface: ViewParent
      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.

      Specified by:
      requestDisallowInterceptTouchEvent in interface ViewParent
      Parameters:
      disallowIntercept - True if the child does not want the parent to intercept touch events.
    • onInterceptTouchEvent

      public boolean onInterceptTouchEvent(@NonNull MotionEvent ev)
      Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.

      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:

      1. You will receive the down event here.
      2. The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal.
      3. For as long as you return false from this function, each following event (up to and including the final up) will be delivered first here and then to the target's onTouchEvent().
      4. If you return true from here, you will not receive any following events: the target view will receive the same event but with the action MotionEvent.ACTION_CANCEL, and all further events will be delivered to your onTouchEvent() method and no longer appear here.
      Parameters:
      ev - The motion event being dispatched down the hierarchy.
      Returns:
      Return true to steal motion events from the children and have them dispatched to this ViewGroup through onTouchEvent(). The current target will receive an ACTION_CANCEL event, and no further messages will be delivered here.
    • requestFocus

      public boolean requestFocus(int direction, @Nullable 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. The rectangle can help give larger views a finer grained hint about where focus is coming from, and therefore, where to show selection, or forward focus change internally.

      A view will not actually take focus if it is not focusable (View.isFocusable() returns false), or if it is focusable and it is not focusable in touch mode (View.isFocusableInTouchMode()) while the device is in touch mode.

      A View will not take focus if it is not visible.

      A View will not take focus if one of its parents has getDescendantFocusability() equal to FOCUS_BLOCK_DESCENDANTS.

      See also View.focusSearch(int), which is what you call to say that you have focus, and you want your parent to look for the next one.

      You may wish to override this method if your custom View has an internal View that it wishes to forward the request to.

      Looks for a view to give focus to respecting the setting specified by getDescendantFocusability().

      Uses onRequestFocusInDescendants(int, Rect) to find focus within the children of this group when appropriate.

      Overrides:
      requestFocus in class View
      Parameters:
      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.
      Returns:
      Whether this view or one of its descendants actually took focus.
      See Also:
    • onRequestFocusInDescendants

      protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
      Look for a descendant to call View.requestFocus() on. Called by requestFocus(int, Rect) when it wants to request focus within its children. Override this to customize how your ViewGroup requests focus within its children.
      Parameters:
      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.
      Returns:
      Whether focus was taken.
    • restoreDefaultFocus

      public boolean restoreDefaultFocus()
      Description copied from class: View
      Gives focus to the default-focus view in the view hierarchy that has this view as a root. If the default-focus view cannot be found, falls back to calling View.requestFocus(int).
      Overrides:
      restoreDefaultFocus in class View
      Returns:
      Whether this view or one of its descendants actually took focus
    • dispatchStartTemporaryDetach

      @Internal public void dispatchStartTemporaryDetach()
      Dispatch View.onStartTemporaryDetach() to this View and its direct children if this is a container View.
      Overrides:
      dispatchStartTemporaryDetach in class View
    • dispatchFinishTemporaryDetach

      @Internal public void dispatchFinishTemporaryDetach()
      Dispatch View.onFinishTemporaryDetach() to this View and its direct children if this is a container View.
      Overrides:
      dispatchFinishTemporaryDetach in class View
    • transformPointToViewLocal

      @Internal protected void transformPointToViewLocal(@NonNull float[] point, @NonNull View child)
    • dispatchKeyEvent

      public boolean dispatchKeyEvent(@NonNull KeyEvent event)
      Description copied from class: View
      Dispatch 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.
      Overrides:
      dispatchKeyEvent in class View
      Parameters:
      event - The key event to be dispatched.
      Returns:
      True if the event was handled, false otherwise.
    • dispatchKeyShortcutEvent

      public boolean dispatchKeyShortcutEvent(@NonNull KeyEvent event)
      Description copied from class: View
      Dispatches a key shortcut event.
      Overrides:
      dispatchKeyShortcutEvent in class View
      Parameters:
      event - The key event to be dispatched.
      Returns:
      True if the event was handled by the view, false otherwise.
    • onResolvePointerIcon

      public PointerIcon onResolvePointerIcon(@NonNull MotionEvent event)
      Description copied from class: View
      Returns the pointer icon for the motion event, or null if it doesn't specify the icon. The default implementation does not care the location or event types, but some subclasses may use it (such as WebViews).
      Overrides:
      onResolvePointerIcon in class View
      Parameters:
      event - The MotionEvent from a mouse
      See Also:
    • addTransientView

      @Internal public void addTransientView(View view, int index)
      This method adds a view to this container at the specified index purely for the purposes of allowing that view to draw even though it is not a normal child of the container. That is, the view does not participate in layout, focus, accessibility, input, or other normal view operations; it is purely an item to be drawn during the normal rendering operation of this container. The index that it is added at is the order in which it will be drawn, with respect to the other views in the container. For example, a transient view added at index 0 will be drawn before all other views in the container because it will be drawn first (including before any real view at index 0). There can be more than one transient view at any particular index; these views will be drawn in the order in which they were added to the list of transient views. The index of transient views can also be greater than the number of normal views in the container; that just means that they will be drawn after all other views are drawn.

      Note that since transient views do not participate in layout, they must be sized manually or, more typically, they should just use the size that they had before they were removed from their container.

      Transient views are useful for handling animations of views that have been removed from the container, but which should be animated out after the removal. Adding these views as transient views allows them to participate in drawing without side-effecting the layout of the container.

      Transient views must always be explicitly removed from the container when they are no longer needed. For example, a transient view which is added in order to fade it out in its old location should be removed once the animation is complete.

      Parameters:
      view - The view to be added. The view must not have a parent.
      index - The index at which this view should be drawn, must be >= 0. This value is relative to the index values in the normal child list of this container, where any transient view at a particular index will be drawn before any normal child at that same index.
    • removeTransientView

      @Internal public void removeTransientView(View view)
      Removes a view from the list of transient views in this container. If there is no such transient view, this method does nothing.
      Parameters:
      view - The transient view to be removed
    • getTransientViewCount

      @Internal public int getTransientViewCount()
      Returns the number of transient views in this container. Specific transient views and the index at which they were added can be retrieved via getTransientView(int) and getTransientViewIndex(int).
      Returns:
      The number of transient views in this container
      See Also:
    • getTransientViewIndex

      @Internal public int getTransientViewIndex(int position)
      Given a valid position within the list of transient views, returns the index of the transient view at that position.
      Parameters:
      position - The position of the index being queried. Must be at least 0 and less than the value returned by getTransientViewCount().
      Returns:
      The index of the transient view stored in the given position if the position is valid, otherwise -1
    • getTransientView

      @Internal public View getTransientView(int position)
      Given a valid position within the list of transient views, returns the transient view at that position.
      Parameters:
      position - The position of the view being queried. Must be at least 0 and less than the value returned by getTransientViewCount().
      Returns:
      The transient view stored in the given position if the position is valid, otherwise null
    • addView

      public void addView(@NonNull View 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.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(Canvas), dispatchDraw(Canvas) or any related method.

      Parameters:
      child - the child view to add
      See Also:
    • addView

      public void addView(@NonNull View child, int index)
      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.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(Canvas), dispatchDraw(Canvas) or any related method.

      Parameters:
      child - the child view to add
      index - the position at which to add the child
      See Also:
    • addView

      public void addView(@NonNull View child, int width, int height)
      Adds a child view with this ViewGroup's default layout parameters and the specified width and height.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(Canvas), dispatchDraw(Canvas) or any related method.

      Parameters:
      child - the child view to add
    • addView

      public void addView(@NonNull View child, @NonNull ViewGroup.LayoutParams params)
      Adds a child view with the specified layout parameters.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(Canvas), dispatchDraw(Canvas) or any related method.

      Specified by:
      addView in interface ViewManager
      Parameters:
      child - the child view to add
      params - the layout parameters to set on the child
    • addView

      public void addView(@NonNull View child, int index, @NonNull ViewGroup.LayoutParams params)
      Adds a child view with the specified layout parameters.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(Canvas), dispatchDraw(Canvas) or any related method.

      Parameters:
      child - the child view to add
      index - the position at which to add the child or -1 to add last
      params - the layout parameters to set on the child
    • updateViewLayout

      public void updateViewLayout(@NonNull View view, @NonNull ViewGroup.LayoutParams params)
      Specified by:
      updateViewLayout in interface ViewManager
    • addViewInLayout

      protected boolean addViewInLayout(@NonNull View child, int index, @NonNull ViewGroup.LayoutParams params)
      Adds a view during layout. This is useful if in your onLayout() method, you need to add more views (as does the list view for example).

      If index is negative, it means put it at the end of the list.

      Parameters:
      child - the view to add to the group
      index - the index at which the child must be added or -1 to add last
      params - the layout parameters to associate with the child
      Returns:
      true if the child was added, false otherwise
    • addViewInLayout

      protected boolean addViewInLayout(@NonNull View child, int index, @NonNull ViewGroup.LayoutParams params, boolean preventRequestLayout)
      Adds a view during layout. This is useful if in your onLayout() method, you need to add more views (as does the list view for example).

      If index is negative, it means put it at the end of the list.

      Parameters:
      child - the view to add to the group
      index - the index at which the child must be added or -1 to add last
      params - the layout parameters to associate with the child
      preventRequestLayout - if true, calling this method will not trigger a layout request on child
      Returns:
      true if the child was added, false otherwise
    • cleanupLayoutState

      protected void cleanupLayoutState(@NonNull View child)
      Prevents the specified child to be laid out during the next layout pass.
      Parameters:
      child - the child on which to perform the cleanup
    • onViewAdded

      protected void onViewAdded(View child)
      Called when a new child is added to this ViewGroup. Overrides should always call super.onViewAdded.
      Parameters:
      child - the added child view
    • onViewRemoved

      protected void onViewRemoved(View child)
      Called when a child view is removed from this ViewGroup. Overrides should always call super.onViewRemoved.
      Parameters:
      child - the removed child view
    • indexOfChild

      public int indexOfChild(View child)
      Returns the position in the group of the specified child view.
      Parameters:
      child - the view for which to get the position
      Returns:
      a positive integer representing the position of the view in the group, or -1 if the view does not exist in the group
    • getChildAt

      public View getChildAt(int index)
      Returns the view at the specified position in the group.
      Parameters:
      index - the position at which to get the view from
      Returns:
      the view at the specified position or null if the position does not exist within the group
    • getChildCount

      public int getChildCount()
      Returns the number of children in the group.
      Returns:
      a positive integer representing the number of children in the group
    • removeView

      public void removeView(@NonNull View view)

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(Canvas), dispatchDraw(Canvas) or any related method.

      Specified by:
      removeView in interface ViewManager
    • removeViewInLayout

      public void removeViewInLayout(@NonNull View view)
      Removes a view during layout. This is useful if in your onLayout() method, you need to remove more views.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(Canvas), dispatchDraw(Canvas) or any related method.

      Parameters:
      view - the view to remove from the group
    • removeViewsInLayout

      public void removeViewsInLayout(int start, int count)
      Removes a range of views during layout. This is useful if in your onLayout() method, you need to remove more views.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(Canvas), dispatchDraw(Canvas) or any related method.

      Parameters:
      start - the index of the first view to remove from the group
      count - the number of views to remove from the group
    • removeViewAt

      public void removeViewAt(int index)
      Removes the view at the specified position in the group.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(Canvas), dispatchDraw(Canvas) or any related method.

      Parameters:
      index - the position in the group of the view to remove
    • removeViews

      public void removeViews(int start, int count)
      Removes the specified range of views from the group.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(Canvas), dispatchDraw(Canvas) or any related method.

      Parameters:
      start - the first position in the group of the range of views to remove
      count - the number of views to remove
    • setLayoutTransition

      public void setLayoutTransition(LayoutTransition transition)
      Sets the LayoutTransition object for this ViewGroup. If the LayoutTransition object is not null, changes in layout which occur because of children being added to or removed from the ViewGroup will be animated according to the animations defined in that LayoutTransition object. By default, the transition object is null (so layout changes are not animated).

      Replacing a non-null transition will cause that previous transition to be canceled, if it is currently running, to restore this container to its correct post-transition state.

      Parameters:
      transition - The LayoutTransition object that will animated changes in layout. A value of null means no transition will run on layout changes.
    • getLayoutTransition

      public LayoutTransition getLayoutTransition()
      Gets the LayoutTransition object for this ViewGroup. If the LayoutTransition object is not null, changes in layout which occur because of children being added to or removed from the ViewGroup will be animated according to the animations defined in that LayoutTransition object. By default, the transition object is null (so layout changes are not animated).
      Returns:
      LayoutTranstion The LayoutTransition object that will animated changes in layout. A value of null means no transition will run on layout changes.
    • removeAllViews

      public void removeAllViews()
      Call this method to remove all child views from the ViewGroup.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(icyllis.modernui.graphics.Canvas), View.dispatchDraw(Canvas) or any related method.

    • removeAllViewsInLayout

      public 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. An example is a Gallery or a ListView, which may "have" 50 children, but actually only render the number of children that can currently fit inside the object on screen. Do not call this method unless you are extending ViewGroup and understand the view measuring and layout pipeline.

      Note: do not invoke this method from View.draw(Canvas), View.onDraw(icyllis.modernui.graphics.Canvas), View.dispatchDraw(Canvas) or any related method.

    • removeDetachedView

      protected void removeDetachedView(@NonNull View child, boolean animate)
      Finishes the removal of a detached view. This method will dispatch the detached from window event and notify the hierarchy change listener.

      This method is intended to be lightweight and makes no assumptions about whether the parent or child should be redrawn. Proper use of this method will include also making any appropriate View.requestLayout() or View.invalidate() calls. For example, callers can post a Runnable which performs a View.requestLayout() on the next frame, after all detach/remove calls are finished, causing layout to be run prior to redrawing the view hierarchy.

      Parameters:
      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
      See Also:
    • attachViewToParent

      protected void attachViewToParent(View child, int index, ViewGroup.LayoutParams params)
      Attaches a view to this view group. Attaching a view assigns this group as the parent, sets the layout parameters and puts the view in the list of children so that it can be retrieved by calling getChildAt(int).

      This method is intended to be lightweight and makes no assumptions about whether the parent or child should be redrawn. Proper use of this method will include also making any appropriate View.requestLayout() or View.invalidate() calls. For example, callers can post a Runnable which performs a View.requestLayout() on the next frame, after all detach/attach calls are finished, causing layout to be run prior to redrawing the view hierarchy.

      This method should be called only for views which were detached from their parent.

      Parameters:
      child - the child to attach
      index - the index at which the child should be attached
      params - the layout parameters of the child
      See Also:
    • detachViewFromParent

      protected void detachViewFromParent(View child)
      Detaches a view from its parent. Detaching a view should be followed either by a call to attachViewToParent(View, int, ViewGroup.LayoutParams) or a call to removeDetachedView(View, boolean). Detachment should only be temporary; reattachment or removal should happen within the same drawing cycle as detachment. When a view is detached, its parent is null and cannot be retrieved by a call to getChildAt(int).
      Parameters:
      child - the child to detach
      See Also:
    • detachViewFromParent

      protected void detachViewFromParent(int index)
      Detaches a view from its parent. Detaching a view should be followed either by a call to attachViewToParent(View, int, ViewGroup.LayoutParams) or a call to removeDetachedView(View, boolean). Detachment should only be temporary; reattachment or removal should happen within the same drawing cycle as detachment. When a view is detached, its parent is null and cannot be retrieved by a call to getChildAt(int).
      Parameters:
      index - the index of the child to detach
      See Also:
    • detachViewsFromParent

      protected void detachViewsFromParent(int start, int count)
      Detaches a range of views from their parents. Detaching a view should be followed either by a call to attachViewToParent(View, int, ViewGroup.LayoutParams) or a call to removeDetachedView(View, boolean). Detachment should only be temporary; reattachment or removal should happen within the same drawing cycle as detachment. When a view is detached, its parent is null and cannot be retrieved by a call to getChildAt(int).
      Parameters:
      start - the first index of the childrend range to detach
      count - the number of children to detach
      See Also:
    • detachAllViewsFromParent

      protected void detachAllViewsFromParent()
      Detaches all views from the parent. Detaching a view should be followed either by a call to attachViewToParent(View, int, ViewGroup.LayoutParams) or a call to removeDetachedView(View, boolean). Detachment should only be temporary; reattachment or removal should happen within the same drawing cycle as detachment. When a view is detached, its parent is null and cannot be retrieved by a call to getChildAt(int).
      See Also:
    • getDescendantFocusability

      public int getDescendantFocusability()
      Gets the descendant focusability of this view group. The descendant focusability defines the relationship between this view group and its descendants when looking for a view to take focus in View.requestFocus(int).
      Returns:
      one of FOCUS_BEFORE_DESCENDANTS, FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS.
    • setDescendantFocusability

      public void setDescendantFocusability(int focusability)
      Set the descendant focusability of this view group. This defines the relationship between this view group and its descendants when looking for a view to take focus in View.requestFocus(int).
      Parameters:
      focusability - one of FOCUS_BEFORE_DESCENDANTS, FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS.
    • requestChildFocus

      public void requestChildFocus(View child, View focused)
      Description copied from interface: ViewParent
      Called when a child of this parent wants focus
      Specified by:
      requestChildFocus in interface ViewParent
      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
    • dispatchWindowFocusChanged

      public void dispatchWindowFocusChanged(boolean hasFocus)
      Description copied from class: View
      Called when the window containing this view gains or loses window focus. ViewGroups should override to route to their children.
      Overrides:
      dispatchWindowFocusChanged in class View
      Parameters:
      hasFocus - True if the window containing this view now has focus, false otherwise.
    • addFocusables

      public void addFocusables(@NonNull ArrayList<View> views, int direction, int focusableMode)
      Description copied from class: View
      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 or only views that can take accessibility focus if accessibility is enabled depending on the focusable mode parameter.
      Overrides:
      addFocusables in class View
      Parameters:
      views - Focusable views found so far or null if all we are interested is the number of focusables.
      direction - The direction of the focus.
    • addTouchables

      public void addTouchables(@NonNull ArrayList<View> views)
      Description copied from class: View
      Add any touchable views that are descendants of this view (possibly including this view if it is touchable itself) to views.
      Overrides:
      addTouchables in class View
      Parameters:
      views - Touchable views found so far
    • addKeyboardNavigationClusters

      public void addKeyboardNavigationClusters(@NonNull Collection<View> views, int direction)
      Description copied from class: View
      Adds any keyboard navigation cluster roots that are descendants of this view (possibly including this view if it is a cluster root itself) to views.
      Overrides:
      addKeyboardNavigationClusters in class View
      Parameters:
      views - Keyboard navigation cluster roots found so far
      direction - Direction to look
    • setTouchscreenBlocksFocus

      public void setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus)
      Set whether this ViewGroup should ignore focus requests for itself and its children. If this option is enabled and the ViewGroup or a descendant currently has focus, focus will proceed forward.
      Parameters:
      touchscreenBlocksFocus - true to enable blocking focus in the presence of a touchscreen
    • getTouchscreenBlocksFocus

      public boolean getTouchscreenBlocksFocus()
      Check whether this ViewGroup should ignore focus requests for itself and its children.
    • childHasTransientStateChanged

      public void childHasTransientStateChanged(View child, boolean childHasTransientState)
      Called when a child view has changed whether it is tracking transient state.
      Specified by:
      childHasTransientStateChanged in interface ViewParent
      Parameters:
      child - Child view whose state has changed
      childHasTransientState - true if this child has transient state
    • hasTransientState

      public boolean hasTransientState()
      Description copied from class: View
      Indicates whether the view is currently tracking transient state that the app should not need to concern itself with saving and restoring, but that the framework should take special note to preserve when possible.

      A view with transient state cannot be trivially rebound from an external data source, such as an adapter binding item views in a list. This may be because the view is performing an animation, tracking user selection of content, or similar.

      Overrides:
      hasTransientState in class View
      Returns:
      true if the view has transient state
    • clearChildFocus

      public void clearChildFocus(View child)
      Description copied from interface: ViewParent
      Called when a child of this parent is giving up focus
      Specified by:
      clearChildFocus in interface ViewParent
      Parameters:
      child - The view that is giving up focus
    • clearFocus

      public void clearFocus()
      Description copied from class: View
      Called when this view wants to give up focus. If focus is cleared View.onFocusChanged(boolean, int, Rect) is called.

      Note: When not in touch-mode, the framework will try to give focus to the first focusable View from the top after focus is cleared. Hence, if this View is the first from the top that can take focus, then all callbacks related to clearing focus will be invoked after which the framework will give focus to this view.

      Overrides:
      clearFocus in class View
    • getFocusedChild

      public View getFocusedChild()
      Returns the focused child of this view, if any. The child may have focus or contain focus.
      Returns:
      the focused child or null.
    • hasFocus

      public boolean hasFocus()
      Returns true if this view has or contains focus
      Overrides:
      hasFocus in class View
      Returns:
      true if this view has or contains focus
    • findFocus

      @Nullable public View findFocus()
      Description copied from class: View
      Find the view in the hierarchy rooted at this view that currently has focus.
      Overrides:
      findFocus in class View
      Returns:
      The view that currently has focus, or null if no focused view can be found.
    • offsetDescendantRectToMyCoords

      public final void offsetDescendantRectToMyCoords(View descendant, Rect rect)
      Offset a rectangle that is in a descendant's coordinate space into our coordinate space.
      Parameters:
      descendant - A descendant of this view
      rect - A rectangle defined in descendant's coordinate space.
    • offsetRectIntoDescendantCoords

      public final void offsetRectIntoDescendantCoords(View descendant, Rect rect)
      Offset a rectangle that is in our coordinate space into an ancestor's coordinate space.
      Parameters:
      descendant - A descendant of this view
      rect - A rectangle defined in descendant's coordinate space.
    • offsetChildrenTopAndBottom

      public void offsetChildrenTopAndBottom(int offset)
      Offset the vertical location of all children of this view by the specified number of pixels.
      Parameters:
      offset - the number of pixels to offset
    • getChildVisibleRect

      public boolean getChildVisibleRect(View child, Rect r, @Nullable Point offset)
      Description copied from interface: ViewParent
      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.

      Specified by:
      getChildVisibleRect in interface ViewParent
      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
    • getChildVisibleRect

      @Internal public boolean getChildVisibleRect(@NonNull View child, Rect r, @Nullable Point offset, boolean forceParentCheck)
      Parameters:
      forceParentCheck - true to guarantee that this call will propagate to all ancestors, false otherwise
    • focusSearch

      public View focusSearch(View focused, int direction)
      Find the nearest view in the specified direction that wants to take focus.
      Specified by:
      focusSearch in interface ViewParent
      Parameters:
      focused - The view that currently has focus
      direction - One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT, or 0 for not applicable.
    • requestChildRectangleOnScreen

      public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate)
      Description copied from interface: ViewParent
      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 content 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
      Specified by:
      requestChildRectangleOnScreen in interface ViewParent
      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
    • focusableViewAvailable

      public void focusableViewAvailable(View v)
      Description copied from interface: ViewParent
      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.
      Specified by:
      focusableViewAvailable in interface ViewParent
      Parameters:
      v - The view that has become newly focusable
    • showContextMenuForChild

      public boolean showContextMenuForChild(View originalView, float x, float y)
      Description copied from interface: ViewParent
      Shows the context menu for the specified view or its ancestors anchored to the specified view-relative coordinate.

      In most cases, a subclass does not need to override this. However, if the subclass is added directly to the window manager (for example, ViewManager.addView(View, ViewGroup.LayoutParams)) then it should override this and show the context menu.

      Specified by:
      showContextMenuForChild in interface ViewParent
      Parameters:
      originalView - the source view where the context menu was first invoked
      x - the X coordinate in pixels relative to the original view to which the menu should be anchored, or Float.NaN to disable anchoring
      y - the Y coordinate in pixels relative to the original view to which the menu should be anchored, or Float.NaN to disable anchoring
      Returns:
      true if the context menu was shown, false otherwise
    • startActionModeForChild

      public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback, int type)
      Description copied from interface: ViewParent
      Start an action mode of a specific type 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, ViewManager.addView(View, ViewGroup.LayoutParams)) then it should override this and start the action mode.

      Specified by:
      startActionModeForChild in interface ViewParent
      Parameters:
      originalView - The source view where the action mode was first invoked
      callback - The callback that will handle lifecycle events for the action mode
      type - One of ActionMode.TYPE_PRIMARY or ActionMode.TYPE_FLOATING.
      Returns:
      The new action mode if it was started, null otherwise
    • setClipToPadding

      public void setClipToPadding(boolean clipToPadding)
      Sets whether this ViewGroup will clip its children to its padding and resize (but not clip) any EdgeEffect to the padded region, if padding is present.

      By default, children are clipped to the padding of their parent ViewGroup. This clipping behavior is only enabled if padding is non-zero.

      Parameters:
      clipToPadding - true to clip children to the padding of the group, and resize (but not clip) any EdgeEffect to the padded region. False otherwise.
    • getClipToPadding

      public boolean getClipToPadding()
      Returns whether this ViewGroup will clip its children to its padding, and resize (but not clip) any EdgeEffect to the padded region, if padding is present.

      By default, children are clipped to the padding of their parent Viewgroup. This clipping behavior is only enabled if padding is non-zero.

      Returns:
      true if this ViewGroup clips children to its padding and resizes (but doesn't clip) any EdgeEffect to the padded region, false otherwise.
    • dispatchSetSelected

      public void dispatchSetSelected(boolean selected)
      Description copied from class: View
      Dispatch setSelected to all of this View's children.
      Overrides:
      dispatchSetSelected in class View
      Parameters:
      selected - The new selected state
      See Also:
    • dispatchSetActivated

      public void dispatchSetActivated(boolean activated)
      Description copied from class: View
      Dispatch setActivated to all of this View's children.
      Overrides:
      dispatchSetActivated in class View
      Parameters:
      activated - The new activated state
      See Also:
    • dispatchSetPressed

      protected void dispatchSetPressed(boolean pressed)
      Description copied from class: View
      Dispatch setPressed to all of this View's children.
      Overrides:
      dispatchSetPressed in class View
      Parameters:
      pressed - The new pressed state
      See Also:
    • dispatchDrawableHotspotChanged

      public void dispatchDrawableHotspotChanged(float x, float y)
      Dispatches drawable hotspot changes to child views that meet at least one of the following criteria:
      Overrides:
      dispatchDrawableHotspotChanged in class View
      Parameters:
      x - hotspot x coordinate
      y - hotspot y coordinate
      See Also:
    • findViewByPredicateTraversal

      @Nullable protected <T extends View> T findViewByPredicateTraversal(@NonNull Predicate<View> predicate, @Nullable View childToSkip)
      Overrides:
      findViewByPredicateTraversal in class View
      Parameters:
      predicate - The predicate to evaluate.
      childToSkip - If not null, ignores this child during the recursive traversal.
      Returns:
      The first view that matches the predicate or null.
    • findViewTraversal

      @Nullable protected <T extends View> T findViewTraversal(int id)
      Overrides:
      findViewTraversal in class View
      Parameters:
      id - the id of the view to be found
      Returns:
      the view of the specified id, null if cannot be found
    • bringChildToFront

      public void bringChildToFront(View child)
      Description copied from interface: ViewParent
      Change the z order of the child, so it's on top of all other children. This ordering change may affect layout, if this container uses an order-dependent layout scheme (e.g., LinearLayout).
      Specified by:
      bringChildToFront in interface ViewParent
      Parameters:
      child - The child to bring to the top of the z order
    • hasBooleanFlag

      protected boolean hasBooleanFlag(int flag)
    • setBooleanFlag

      protected void setBooleanFlag(int flag, boolean value)
    • isChildrenDrawingOrderEnabled

      protected boolean isChildrenDrawingOrderEnabled()
      Indicates whether the ViewGroup is drawing its children in the order defined by getChildDrawingOrder(int, int).
      Returns:
      true if children drawing order is defined by getChildDrawingOrder(int, int), false otherwise
      See Also:
    • setChildrenDrawingOrderEnabled

      protected void setChildrenDrawingOrderEnabled(boolean enabled)
      Tells the ViewGroup whether to draw its children in the order defined by the method getChildDrawingOrder(int, int).

      Note that View#getZ() reordering, done by View.dispatchDraw(Canvas), will override custom child ordering done via this method.

      Parameters:
      enabled - true if the order of the children when drawing is determined by getChildDrawingOrder(int, int), false otherwise
      See Also:
    • getChildDrawingOrder

      protected int getChildDrawingOrder(int childCount, int drawingPosition)
      Converts drawing order position to container position. Override this if you want to change the drawing order of children. By default, it returns drawingPosition.

      NOTE: In order for this method to be called, you must enable child ordering first by calling setChildrenDrawingOrderEnabled(boolean).

      Parameters:
      drawingPosition - the drawing order position.
      Returns:
      the container position of a child for this drawing order position.
      See Also:
    • getChildDrawingOrder

      public final int getChildDrawingOrder(int drawingPosition)
      Converts drawing order position to container position.

      Children are not necessarily drawn in the order in which they appear in the container. ViewGroups can enable a custom ordering via setChildrenDrawingOrderEnabled(boolean). This method returns the container position of a child that appears in the given position in the current drawing order.

      Parameters:
      drawingPosition - the drawing order position.
      Returns:
      the container position of a child for this drawing order position.
      See Also:
    • drawableStateChanged

      protected void drawableStateChanged()
      Description copied from class: View
      This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

      If the View has a StateListAnimator, it will also be called to run necessary state change animations.

      Be sure to call through to the superclass when overriding this function.

      Overrides:
      drawableStateChanged in class View
      See Also:
    • jumpDrawablesToCurrentState

      public void jumpDrawablesToCurrentState()
      Description copied from class: View
      Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

      Also calls StateListAnimator.jumpToCurrentState() if there is a StateListAnimator attached to this view.

      Overrides:
      jumpDrawablesToCurrentState in class View
    • onCreateDrawableState

      @NonNull protected int[] onCreateDrawableState(int extraSpace)
      Description copied from class: View
      Generate the new Drawable state for this view. This is called by the view system when the cached Drawable state is determined to be invalid. To retrieve the current state, you should use View.getDrawableState().
      Overrides:
      onCreateDrawableState in class View
      Parameters:
      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.
      Returns:
      an array holding the current Drawable state of the view.
      See Also:
    • setAddStatesFromChildren

      public void setAddStatesFromChildren(boolean addsStates)
      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.
    • addStatesFromChildren

      public boolean addStatesFromChildren()
      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.
    • childDrawableStateChanged

      public void childDrawableStateChanged(View child)
      If addStatesFromChildren() is true, refreshes this group's drawable state (to include the states from its children).
      Specified by:
      childDrawableStateChanged in interface ViewParent
      Parameters:
      child - The child whose drawable state has changed.
    • requestTransitionStart

      @Internal public void requestTransitionStart(LayoutTransition transition)
      This method is called by LayoutTransition when there are 'changing' animations that need to start after the layout/setup phase. The request is forwarded to the ViewAncestor, who starts all pending transitions prior to the drawing phase in the current traversal.
      Parameters:
      transition - The LayoutTransition to be started on the next traversal.
    • resolveRtlPropertiesIfNeeded

      @Internal public boolean resolveRtlPropertiesIfNeeded()
      Description copied from class: View
      Resolve all RTL related properties.
      Overrides:
      resolveRtlPropertiesIfNeeded in class View
      Returns:
      true if resolution of RTL properties has been done
    • resolveLayoutDirection

      @Internal public boolean resolveLayoutDirection()
      Description copied from class: View
      Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing that the parent directionality can and will be resolved before its children.
      Overrides:
      resolveLayoutDirection in class View
      Returns:
      true if resolution has been done, false otherwise.
    • resolveTextDirection

      @Internal public boolean resolveTextDirection()
      Description copied from class: View
      Resolve the text direction.
      Overrides:
      resolveTextDirection in class View
      Returns:
      true if resolution has been done, false otherwise.
    • resolveTextAlignment

      @Internal public boolean resolveTextAlignment()
      Description copied from class: View
      Resolve the text alignment.
      Overrides:
      resolveTextAlignment in class View
      Returns:
      true if resolution has been done, false otherwise.
    • resolvePadding

      @Internal public void resolvePadding()
      Description copied from class: View
      Resolves padding depending on layout direction, if applicable, and recomputes internal padding values to adjust for scroll bars.
      Overrides:
      resolvePadding in class View
    • resolveDrawables

      @Internal protected void resolveDrawables()
      Description copied from class: View
      Resolve the Drawables depending on the layout direction. This is implicitly supposing that the View directionality can and will be resolved before its Drawables.

      Will call View.onResolveDrawables(int) when resolution is done.

      Overrides:
      resolveDrawables in class View
    • resolveLayoutParams

      @Internal public void resolveLayoutParams()
      Description copied from class: View
      Resolve the layout parameters depending on the resolved layout direction
      Overrides:
      resolveLayoutParams in class View
    • resetResolvedDrawables

      @Internal protected void resetResolvedDrawables()
      Overrides:
      resetResolvedDrawables in class View
    • getClipChildren

      public boolean getClipChildren()
      Returns whether this group's children are clipped to their bounds before drawing. The default value is true.
      Returns:
      True if the group's children will be clipped to their bounds, false otherwise.
      See Also:
    • setClipChildren

      public void setClipChildren(boolean clipChildren)
      By default, children are clipped to their bounds before drawing. This allows view groups to override this behavior for animations, etc.
      Parameters:
      clipChildren - true to clip children to their bounds, false otherwise
    • measureChildren

      protected void measureChildren(int widthMeasureSpec, int heightMeasureSpec)
      Ask all the children of this view to measure themselves, taking into account both the MeasureSpec requirements for this view and its padding. We skip children that are in the GONE state The heavy lifting is done in getChildMeasureSpec.
      Parameters:
      widthMeasureSpec - The width requirements for this view
      heightMeasureSpec - The height requirements for this view
    • measureChild

      protected void measureChild(@NonNull View child, int parentWidthSpec, int parentHeightSpec)
      Ask one of the children of this view to measure itself, taking into account both the MeasureSpec requirements for this view and its padding. The heavy lifting is done in getChildMeasureSpec.
      Parameters:
      child - The child to measure
      parentWidthSpec - The width requirements for this view
      parentHeightSpec - The height requirements for this view
    • measureChildWithMargins

      protected void measureChildWithMargins(@NonNull View child, int parentWidthSpec, int widthUsed, int parentHeightSpec, 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. The child must have MarginLayoutParams The heavy lifting is done in getChildMeasureSpec.
      Parameters:
      child - The child to measure
      parentWidthSpec - 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)
      parentHeightSpec - 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)
    • getChildMeasureSpec

      public 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. This method figures out the right MeasureSpec for one dimension (height or width) of one child view.

      The goal is to combine information from our MeasureSpec with the LayoutParams of the child to get the best possible results. For example, if the this view knows its size (because its MeasureSpec has a mode of EXACTLY), and the child has indicated in its LayoutParams that it wants to be the same size as the parent, the parent should ask the child to layout given an exact size.

      Parameters:
      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
      Returns:
      a MeasureSpec integer for the child
    • clearDisappearingChildren

      public void clearDisappearingChildren()
      Removes any pending animations for views that have been removed. Call this if you don't want animations for exiting views to stack up.
    • startViewTransition

      public void startViewTransition(@NonNull View view)
      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. This allows animations, such as those used by Fragment and LayoutTransition to animate the removal of views. A call to this method should always be accompanied by a later call to endViewTransition(View), such as after an animation on the View has finished, so that the View finally gets removed.
      Parameters:
      view - The View object to be kept visible even if it gets removed from its parent.
    • endViewTransition

      public void endViewTransition(View view)
      This method should always be called following an earlier call to startViewTransition(View). The given View is finally removed from its parent and will no longer be displayed. Note that this method does not perform the functionality of removing a view from its parent; it just discontinues the display of a View that has previously been removed.
      Parameters:
      view - The View object that has been removed but is being kept around in the visible hierarchy by an earlier call to startViewTransition(View).
    • suppressLayout

      public void suppressLayout(boolean suppress)
      Tells this ViewGroup to suppress all layout() calls until layout suppression is disabled with a later call to suppressLayout(false). When layout suppression is disabled, a requestLayout() call is sent if layout() was attempted while layout was being suppressed.
    • isLayoutSuppressed

      public boolean isLayoutSuppressed()
      Returns whether layout calls on this container are currently being suppressed, due to an earlier call to suppressLayout(boolean).
      Returns:
      true if layout calls are currently suppressed, false otherwise.
    • internalSetPadding

      @Internal protected void internalSetPadding(int left, int top, int right, int bottom)
      Overrides:
      internalSetPadding in class View
    • onChildVisibilityChanged

      @Internal protected void onChildVisibilityChanged(View child, int oldVisibility, int newVisibility)
      Called when a view's visibility has changed. Notify the parent to take any appropriate action.
      Parameters:
      child - The view whose visibility has changed
      oldVisibility - The previous visibility value (GONE, INVISIBLE, or VISIBLE).
      newVisibility - The new visibility value (GONE, INVISIBLE, or VISIBLE).
    • dispatchVisibilityChanged

      protected void dispatchVisibilityChanged(@NonNull View changedView, int visibility)
      Description copied from class: View
      Dispatch a view visibility change down the view hierarchy. ViewGroups should override to route to their children.
      Overrides:
      dispatchVisibilityChanged in class View
      Parameters:
      changedView - The view whose visibility changed. Could be 'this' or an ancestor view.
      visibility - The new visibility of changedView: View.VISIBLE, View.INVISIBLE or View.GONE.
    • dispatchWindowVisibilityChanged

      public void dispatchWindowVisibilityChanged(int visibility)
      Description copied from class: View
      Dispatch a window visibility change down the view hierarchy. ViewGroups should override to route to their children.
      Overrides:
      dispatchWindowVisibilityChanged in class View
      Parameters:
      visibility - The new visibility of the window.
      See Also:
    • shouldDelayChildPressedState

      public boolean shouldDelayChildPressedState()
      Return true if the pressed state should be delayed for children or descendants of this ViewGroup. Generally, this should be done for containers that can scroll, such as a List. This prevents the pressed state from appearing when the user is actually trying to scroll the content.

      The default implementation returns true for compatibility reasons. Subclasses that do not scroll should generally override this method and return false.

    • onStartNestedScroll

      public boolean onStartNestedScroll(@NonNull View child, @NonNull View target, int axes, int type)
      Description copied from interface: ViewParent
      React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.

      This method will be called in response to a descendant view invoking View.startNestedScroll(int, int). Each parent up the view hierarchy will be given an opportunity to respond and claim the nested scrolling operation by returning true.

      This method may be overridden by ViewParent implementations to indicate when the view is willing to support a nested scrolling operation that is about to begin. If it returns true, this ViewParent will become the target view's nested scrolling parent for the duration of the scroll operation in progress. When the nested scroll is finished this ViewParent will receive a call to ViewParent.onStopNestedScroll(View, int).

      Specified by:
      onStartNestedScroll in interface ViewParent
      Parameters:
      child - Direct child of this ViewParent containing target
      target - View that initiated the nested scroll
      axes - Flags consisting of View.SCROLL_AXIS_HORIZONTAL, View.SCROLL_AXIS_VERTICAL or both
      type - the type of input which cause this scroll event
      Returns:
      true if this ViewParent accepts the nested scroll operation
    • onNestedScrollAccepted

      public void onNestedScrollAccepted(@NonNull View child, @NonNull View target, int axes, int type)
      Description copied from interface: ViewParent
      React to the successful claiming of a nested scroll operation.

      This method will be called after onStartNestedScroll returns true. It offers an opportunity for the view and its superclasses to perform initial configuration for the nested scroll. Implementations of this method should always call their superclasses' implementation of this method if one is present.

      Specified by:
      onNestedScrollAccepted in interface ViewParent
      Parameters:
      child - Direct child of this ViewParent containing target
      target - View that initiated the nested scroll
      axes - Flags consisting of View.SCROLL_AXIS_HORIZONTAL, View.SCROLL_AXIS_VERTICAL or both
      type - the type of input which cause this scroll event
      See Also:
    • onStopNestedScroll

      public void onStopNestedScroll(@NonNull View target, int type)
      Description copied from interface: ViewParent
      React to a nested scroll operation ending.

      Perform cleanup after a nested scrolling operation. This method will be called when a nested scroll stops, for example when a nested touch scroll ends with a MotionEvent.ACTION_UP or MotionEvent.ACTION_CANCEL event. Implementations of this method should always call their superclasses' implementation of this method if one is present.

      Specified by:
      onStopNestedScroll in interface ViewParent
      Parameters:
      target - View that initiated the nested scroll
      type - the type of input which cause this scroll event
    • onNestedScroll

      public void onNestedScroll(@NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type, @NonNull int[] consumed)
      Description copied from interface: ViewParent
      React to a nested scroll in progress.

      This method will be called when the ViewParent's current nested scrolling child view dispatches a nested scroll event. To receive calls to this method the ViewParent must have previously returned true for a call to ViewParent.onStartNestedScroll(View, View, int, int).

      Both the consumed and unconsumed portions of the scroll distance are reported to the ViewParent. An implementation may choose to use the consumed portion to match or chase scroll position of multiple child elements, for example. The unconsumed portion may be used to allow continuous dragging of multiple scrolling or draggable elements, such as scrolling a list within a vertical drawer where the drawer begins dragging once the edge of inner scrolling content is reached.

      This method is called when a nested scrolling child invokes View.dispatchNestedScroll(int, int, int, int, int[], int, int[])} or one of methods it overloads.

      An implementation must report how many pixels of the x and y scroll distances were consumed by this nested scrolling parent by adding the consumed distances to the consumed parameter. consumed should also be passed up to it's nested scrolling parent so that the parent may also add any scroll distance it consumes. Index 0 corresponds to dx and index 1 corresponds to dy.

      Specified by:
      onNestedScroll in interface ViewParent
      Parameters:
      target - The descendant view controlling the nested scroll
      dxConsumed - Horizontal scroll distance in pixels already consumed by target
      dyConsumed - Vertical scroll distance in pixels already consumed by target
      dxUnconsumed - Horizontal scroll distance in pixels not consumed by target
      dyUnconsumed - Vertical scroll distance in pixels not consumed by target
      type - the type of input which cause this scroll event
      consumed - Output. Upon this method returning, will contain the scroll distances consumed by this nested scrolling parent and the scroll distances consumed by any other parent up the view hierarchy
      See Also:
    • onNestedPreScroll

      public void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int[] consumed, int type)
      Description copied from interface: ViewParent
      React to a nested scroll in progress before the target view consumes a portion of the scroll.

      When working with nested scrolling often the parent view may want an opportunity to consume the scroll before the nested scrolling child does. An example of this is a drawer that contains a scrollable list. The user will want to be able to scroll the list fully into view before the list itself begins scrolling.

      onNestedPreScroll is called when a nested scrolling child invokes View.dispatchNestedPreScroll(int, int, int[], int[], int). The implementation should report how any pixels of the scroll reported by dx, dy were consumed in the consumed array. Index 0 corresponds to dx and index 1 corresponds to dy. This parameter will never be null. Initial values for consumed[0] and consumed[1] will always be 0.

      Specified by:
      onNestedPreScroll in interface ViewParent
      Parameters:
      target - View that initiated the nested scroll
      dx - Horizontal scroll distance in pixels
      dy - Vertical scroll distance in pixels
      consumed - Output. The horizontal and vertical scroll distance consumed by this parent
      type - the type of input which cause this scroll event
    • onNestedFling

      public boolean onNestedFling(@NonNull View target, float velocityX, float velocityY, boolean consumed)
      Description copied from interface: ViewParent
      Request a fling from a nested scroll.

      This method signifies that a nested scrolling child has detected suitable conditions for a fling. Generally this means that a touch scroll has ended with a velocity in the direction of scrolling that meets or exceeds the minimum fling velocity along a scrollable axis.

      If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.

      Specified by:
      onNestedFling in interface ViewParent
      Parameters:
      target - View that initiated the nested scroll
      velocityX - Horizontal velocity in pixels per second
      velocityY - Vertical velocity in pixels per second
      consumed - true if the child consumed the fling, false otherwise
      Returns:
      true if this parent consumed or otherwise reacted to the fling
    • onNestedPreFling

      public boolean onNestedPreFling(@NonNull View target, float velocityX, float velocityY)
      Description copied from interface: ViewParent
      React to a nested fling before the target view consumes it.

      This method signifies that a nested scrolling child has detected a fling with the given velocity along each axis. Generally this means that a touch scroll has ended with a velocity in the direction of scrolling that meets or exceeds the minimum fling velocity along a scrollable axis.

      If a nested scrolling parent is consuming motion as part of a pre-scroll, it may be appropriate for it to also consume the pre-fling to complete that same motion. By returning true from this method, the parent indicates that the child should not fling its own internal content as well.

      Specified by:
      onNestedPreFling in interface ViewParent
      Parameters:
      target - View that initiated the nested scroll
      velocityX - Horizontal velocity in pixels per second
      velocityY - Vertical velocity in pixels per second
      Returns:
      true if this parent consumed the fling ahead of the target view
    • getNestedScrollAxes

      public int getNestedScrollAxes()
      Description copied from interface: ViewParent
      Return the current axes of nested scrolling for this NestedScrollingParent.

      A NestedScrollingParent returning something other than View.SCROLL_AXIS_NONE is currently acting as a nested scrolling parent for one or more descendant views in the hierarchy.

      Specified by:
      getNestedScrollAxes in interface ViewParent
      Returns:
      Flags indicating the current axes of nested scrolling
      See Also:
    • onSetLayoutParams

      @Internal protected void onSetLayoutParams(View child, ViewGroup.LayoutParams layoutParams)
    • generateLayoutParams

      @NonNull protected ViewGroup.LayoutParams generateLayoutParams(@NonNull ViewGroup.LayoutParams p)
      Returns a safe set of layout parameters based on the supplied layout params. When a ViewGroup is passed a View whose layout params do not pass the test of checkLayoutParams(LayoutParams), this method is invoked. This method should return a new set of layout params suitable for this ViewGroup, possibly by copying the appropriate attributes from the specified set of layout params.
      Parameters:
      p - The layout parameters to convert into a suitable set of layout parameters for this ViewGroup.
      Returns:
      an instance of ViewGroup.LayoutParams or one of its descendants
    • generateDefaultLayoutParams

      @NonNull protected ViewGroup.LayoutParams generateDefaultLayoutParams()
      Returns a set of default layout parameters. These parameters are requested when the View passed to addView(View) has no layout parameters already set. If null is returned, an exception is thrown from addView.
      Returns:
      a set of default layout parameters
    • checkLayoutParams

      protected boolean checkLayoutParams(@Nullable ViewGroup.LayoutParams p)
      Check whether given params fit to this view group.

      See also generateLayoutParams(LayoutParams) See also generateDefaultLayoutParams()

      Parameters:
      p - layout params to check
      Returns:
      if params matched to this view group