ViewGroup
abstract class ViewGroup : View, ViewManager, ViewParent
| kotlin.Any | ||
| ↳ | android.view.View | |
| ↳ | android.view.ViewGroup | |
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 android.view.ViewGroup.LayoutParams class which serves as the base class for layouts parameters.
Also see LayoutParams for layout attributes.
Here is a complete implementation of a custom ViewGroup that implements a simple android.widget.FrameLayout along with the ability to stack children in left and right gutters.
If you are implementing XML layout attributes as shown in the example, this is the corresponding definition for them that would go in res/values/attrs.xml:
Finally the layout manager can be used in an XML layout like so:
Summary
| Nested classes | |
|---|---|
| open |
LayoutParams are used by views to tell their parents how they want to be laid out. |
| open |
Per-child layout information for layouts that support margins. |
| abstract |
Interface definition for a callback to be invoked when the hierarchy within this view changed. |
| XML attributes | |
|---|---|
android:addStatesFromChildren |
Sets whether this ViewGroup's drawable states also include its children's drawable states. |
android:alwaysDrawnWithCache |
Defines whether the ViewGroup should always draw its children using their drawing cache or not. |
android:animateLayoutChanges |
Defines whether changes in layout (caused by adding and removing items) should cause a LayoutTransition to run. |
android:animationCache |
Defines whether layout animations should create a drawing cache for their children. |
android:clipChildren |
Defines whether a child is limited to draw inside of its bounds or not. |
android:clipToPadding |
Defines whether the ViewGroup will clip its children and resize (but not clip) any EdgeEffect to its padding, if padding is not zero. |
android:descendantFocusability |
Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus. |
android:layoutAnimation |
Defines the layout animation to use the first time the ViewGroup is laid out. |
android:layoutMode |
Defines the layout mode of this ViewGroup. |
android:persistentDrawingCache |
Defines the persistence of the drawing cache. |
android:splitMotionEvents |
Sets whether this ViewGroup should split MotionEvents to separate child views during touch event dispatch. |
| Inherited XML attributes | |
|---|---|
| Constants | |
|---|---|
| static Int |
We clip to padding when FLAG_CLIP_TO_PADDING and FLAG_PADDING_NOT_NULL are set at the same time. |
| static Int |
This view will get focus only if none of its descendants want it. |
| static Int |
This view will get focus before any of its descendants. |
| static Int |
This view will block any of its descendants from getting focus, even if they are focusable. |
| static Int |
This constant is a |
| static Int |
This constant is a |
| static Int |
Used to indicate that all drawing caches should be kept in memory. |
| static Int |
Used to indicate that the animation drawing cache should be kept in memory. |
| static Int |
Used to indicate that no drawing cache should be kept in memory. |
| static Int |
Used to indicate that the scrolling drawing cache should be kept in memory. |
| Inherited constants | |
|---|---|
| Public constructors | |
|---|---|
ViewGroup(context: Context!, attrs: AttributeSet!) |
|
ViewGroup(context: Context!, attrs: AttributeSet!, defStyleAttr: Int) |
|
ViewGroup(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int) |
|
| Public methods | |
|---|---|
| open Unit |
addChildrenForAccessibility(outChildren: ArrayList<View!>!)Adds the children of this View relevant for accessibility to the given list as output. |
| open Unit |
addExtraDataToAccessibilityNodeInfo(info: AccessibilityNodeInfo, extraDataKey: String, arguments: Bundle?)Adds extra data to an |
| open Unit |
addFocusables(views: ArrayList<View!>!, direction: Int, focusableMode: Int)Adds any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. |
| open Unit |
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. |
| open Boolean |
Returns whether this ViewGroup's drawable states also include its children's drawable states. |
| open Unit |
addTouchables(views: ArrayList<View!>!)Add any touchable views that are descendants of this view (possibly including this view if it is touchable itself) to views. |
| open Unit |
Adds a child view. |
| open Unit |
addView(child: View!, params: ViewGroup.LayoutParams!)Adds a child view with the specified layout parameters. |
| open Unit |
Adds a child view. |
| open Unit |
addView(child: View!, index: Int, params: ViewGroup.LayoutParams!)Adds a child view with the specified layout parameters. |
| open Unit |
Adds a child view with this ViewGroup's default layout parameters and the specified width and height. |
| open Unit |
bringChildToFront(child: View!)Change the z order of the child so it's on top of all other children. |
| open Unit |
childDrawableStateChanged(child: View)If |
| open Unit |
childHasTransientStateChanged(child: View, childHasTransientState: Boolean)Called when a child view has changed whether or not it is tracking transient state. |
| open Unit |
clearChildFocus(child: View!)Called when a child of this parent is giving up focus |
| open Unit |
Removes any pending animations for views that have been removed. |
| open Unit |
Called when this view wants to give up focus. |
| open WindowInsets! |
dispatchApplyWindowInsets(insets: WindowInsets!)Request to apply the given window insets to this view or another view in its subtree. |
| open Boolean |
dispatchCapturedPointerEvent(event: MotionEvent!)Pass a captured pointer event down to the focused view. |
| open Unit |
dispatchConfigurationChanged(newConfig: Configuration!)Dispatch a notification about a resource configuration change down the view hierarchy. |
| open Unit |
dispatchCreateViewTranslationRequest(viewIds: MutableMap<AutofillId!, LongArray!>, supportedFormats: IntArray, capability: TranslationCapability!, requests: MutableList<ViewTranslationRequest!>)Dispatch to collect the |
| open Unit |
dispatchDisplayHint(hint: Int)Dispatch a hint about whether this view is displayed. |
| open Boolean |
dispatchDragEvent(event: DragEvent!)Detects if this View is enabled and has a drag event listener. |
| open Unit |
dispatchDrawableHotspotChanged(x: Float, y: Float)Dispatches drawable hotspot changes to child views that meet at least one of the following criteria:
|
| open Unit |
Dispatch |
| open Boolean |
dispatchKeyEvent(event: KeyEvent!)Dispatch a key event to the next view on the focus path. |
| open Boolean |
dispatchKeyEventPreIme(event: KeyEvent!)Dispatch a key event before it is processed by any input method associated with the view hierarchy. |
| open Boolean |
dispatchKeyShortcutEvent(event: KeyEvent!)Dispatches a key shortcut event. |
| open Unit |
dispatchPointerCaptureChanged(hasCapture: Boolean) |
| open Unit |
dispatchProvideAutofillStructure(structure: ViewStructure, flags: Int)Dispatches creation of a |
| open Unit |
dispatchProvideStructure(structure: ViewStructure!)Dispatch creation of |
| open Unit |
dispatchScrollCaptureSearch(localVisibleRect: Rect, windowOffset: Point, targets: Consumer<ScrollCaptureTarget!>)Handle the scroll capture search request by checking this view if applicable, then to each child view. |
| open Unit |
dispatchSetActivated(activated: Boolean)Dispatch setActivated to all of this View's children. |
| open Unit |
dispatchSetSelected(selected: Boolean)Dispatch setSelected to all of this View's children. |
| open Unit |
Dispatch |
| open Unit |
dispatchSystemUiVisibilityChanged(visible: Int)Dispatch callbacks to |
| open Boolean |
Pass the touch screen motion event down to the target view, or this view if it is the target. |
| open Boolean |
dispatchTrackballEvent(event: MotionEvent!)Pass a trackball motion event down to the focused view. |
| open Boolean |
dispatchUnhandledMove(focused: View!, direction: Int)This method is the last chance for the focused view and its ancestors to respond to an arrow key. |
| open Unit |
dispatchWindowFocusChanged(hasFocus: Boolean)Called when the window containing this view gains or loses window focus. |
| open Unit |
Dispatches |
| open Unit |
Dispatches |
| open WindowInsets |
dispatchWindowInsetsAnimationProgress(insets: WindowInsets, runningAnimations: MutableList<WindowInsetsAnimation!>)Dispatches |
| open WindowInsetsAnimation.Bounds |
dispatchWindowInsetsAnimationStart(animation: WindowInsetsAnimation, bounds: WindowInsetsAnimation.Bounds)Dispatches |
| open Unit |
dispatchWindowSystemUiVisiblityChanged(visible: Int)Dispatch callbacks to |
| open Unit |
dispatchWindowVisibilityChanged(visibility: Int)Dispatch a window visibility change down the view hierarchy. |
| open Unit |
endViewTransition(view: View!)This method should always be called following an earlier call to |
| open View! |
Find the view in the hierarchy rooted at this view that currently has focus. |
| open OnBackInvokedDispatcher? |
findOnBackInvokedDispatcherForChild(child: View, requester: View)Walk up the View hierarchy to find the nearest |
| open Unit |
findViewsWithText(outViews: ArrayList<View!>!, text: CharSequence!, flags: Int)Finds the Views that contain given text. |
| open View! |
focusSearch(focused: View!, direction: Int)Find the nearest view in the specified direction that wants to take focus. |
| open Unit |
Tells the parent that a new focusable view has become available. |
| open Boolean |
gatherTransparentRegion(region: Region?)This is used by the ViewRoot to perform an optimization when the view hierarchy contains one or several SurfaceView. |
| open ViewGroup.LayoutParams! |
generateLayoutParams(attrs: AttributeSet!)Returns a new set of layout parameters based on the supplied attributes set. |
| open CharSequence! |
Return the class name of this object to be used for accessibility purposes. |
| open View! |
getChildAt(index: Int)Returns the view at the specified position in the group. |
| open Int |
Returns the number of children in the group. |
| Int |
getChildDrawingOrder(drawingPosition: Int)Converts drawing order position to container position. |
| open static Int |
getChildMeasureSpec(spec: Int, padding: Int, childDimension: Int)Does the hard part of measureChildren: figuring out the MeasureSpec to pass to a particular child. |
| open Boolean |
getChildVisibleRect(child: View!, r: Rect!, offset: Point!)Compute the visible part of a rectangular region defined in terms of a child view's coordinates. |
| open Boolean |
Returns whether this group's children are clipped to their bounds before drawing. |
| open Boolean |
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. |
| open Int |
Gets the descendant focusability of this view group. |
| open View! |
Returns the focused child of this view, if any. |
| open LayoutAnimationController! |
Returns the layout animation controller used to animate the group's children. |
| open Animation.AnimationListener! |
Returns the animation listener to which layout animation events are sent. |
| open Int |
Returns the basis of alignment during layout operations on this ViewGroup: either |
| open LayoutTransition! |
Gets the LayoutTransition object for this ViewGroup. |
| open Int |
Return the current axes of nested scrolling for this ViewGroup. |
| open ViewGroupOverlay! |
Returns the ViewGroupOverlay for this view group, creating it if it does not yet exist. |
| open Int |
Returns an integer indicating what types of drawing caches are kept in memory. |
| open Boolean |
Check whether this ViewGroup should ignore focus requests for itself and its children. |
| open Boolean |
hasFocus()Returns true if this view has or contains focus |
| open Boolean |
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. |
| open Int |
indexOfChild(child: View!)Returns the position in the group of the specified child view. |
| Unit |
invalidateChild(child: View!, dirty: Rect!)Don't call or override this method. |
| open ViewParent! |
invalidateChildInParent(location: IntArray!, dirty: Rect!)Don't call or override this method. |
| open Boolean |
Indicates whether this ViewGroup will always try to draw its children using their drawing cache. |
| open Boolean |
Indicates whether the children's drawing cache is used during a layout animation. |
| open Boolean |
Returns whether layout calls on this container are currently being suppressed, due to an earlier call to |
| open Boolean |
Returns true if MotionEvents dispatched to this ViewGroup can be split to multiple children. |
| open Boolean |
Returns true if this ViewGroup should be considered as a single entity for removal when executing an Activity transition. |
| open Unit |
Call |
| Unit |
Assign a size and position to a view and all of its descendants |
| open Unit |
notifySubtreeAccessibilityStateChanged(child: View, source: View, changeType: Int)Notifies a view parent that the accessibility state of one of its descendants has changed and that the structure of the subtree is different. |
| Unit |
offsetDescendantRectToMyCoords(descendant: View!, rect: Rect!)Offset a rectangle that is in a descendant's coordinate space into our coordinate space. |
| Unit |
offsetRectIntoDescendantCoords(descendant: View!, rect: Rect!)Offset a rectangle that is in our coordinate space into an ancestor's coordinate space. |
| open Unit |
onDescendantInvalidated(child: View, target: View)The target View has been invalidated, or has had a drawing property changed that requires the hierarchy to re-render. |
| open Boolean |
onInterceptHoverEvent(event: MotionEvent!)Implement this method to intercept hover events before they are handled by child views. |
| open Boolean |
Implement this method to intercept all touch screen motion events. |
| open Boolean |
onNestedFling(target: View, velocityX: Float, velocityY: Float, consumed: Boolean)Request a fling from a nested scroll. |
| open Boolean |
onNestedPreFling(target: View, velocityX: Float, velocityY: Float)React to a nested fling before the target view consumes it. |
| open Boolean |
onNestedPrePerformAccessibilityAction(target: View, action: Int, args: Bundle?)React to an accessibility action delegated by a target descendant view before the target processes it. |
| open Unit |
onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray)React to a nested scroll in progress before the target view consumes a portion of the scroll. |
| open Unit |
onNestedScroll(target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int)React to a nested scroll in progress. |
| open Unit |
onNestedScrollAccepted(child: View, target: View, axes: Int)React to the successful claiming of a nested scroll operation. |
| open Boolean |
onRequestSendAccessibilityEvent(child: View!, event: AccessibilityEvent!)Called when a child has requested sending an |
| open PointerIcon! |
onResolvePointerIcon(event: MotionEvent!, pointerIndex: Int)Resolve the pointer icon that should be used for specified pointer in the motion event. |
| open Boolean |
onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int)React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate. |
| open Unit |
onStopNestedScroll(child: View)React to a nested scroll operation ending. |
| open Unit |
onViewAdded(child: View!)Called when a new child is added to this ViewGroup. |
| open Unit |
onViewRemoved(child: View!)Called when a child view is removed from this ViewGroup. |
| open Unit |
propagateRequestedFrameRate(frameRate: Float, forceOverride: Boolean)You can set the preferred frame rate for a ViewGroup and its children using a positive number or by specifying the preferred frame rate category using constants, including REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE, REQUESTED_FRAME_RATE_CATEGORY_LOW, REQUESTED_FRAME_RATE_CATEGORY_NORMAL, REQUESTED_FRAME_RATE_CATEGORY_HIGH. |
| open Unit |
recomputeViewAttributes(child: View!)Tell view hierarchy that the global view attributes need to be re-evaluated. |
| open Unit |
Call this method to remove all child views from the ViewGroup. |
| open Unit |
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. |
| open Unit |
removeView(view: View!)Note: do not invoke this method from |
| open Unit |
removeViewAt(index: Int)Removes the view at the specified position in the group. |
| open Unit |
removeViewInLayout(view: View!)Removes a view during layout. |
| open Unit |
removeViews(start: Int, count: Int)Removes the specified range of views from the group. |
| open Unit |
removeViewsInLayout(start: Int, count: Int)Removes a range of views during layout. |
| open Unit |
requestChildFocus(child: View!, focused: View!)Called when a child of this parent wants focus |
| open Boolean |
requestChildRectangleOnScreen(child: View, rectangle: Rect!, immediate: Boolean)Called when a child of this group wants a particular rectangle to be positioned onto the screen. |
| open Unit |
requestDisallowInterceptTouchEvent(disallowIntercept: Boolean)Called when a child does not want this parent and its ancestors to intercept touch events with |
| open Boolean |
requestFocus(direction: Int, previouslyFocusedRect: Rect!)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. |
| open Boolean |
requestSendAccessibilityEvent(child: View, event: AccessibilityEvent!)Called by a child to request from its parent to send an |
| open Unit |
requestTransparentRegion(child: View!)Called when a child wants the view hierarchy to gather and report transparent regions to the window compositor. |
| open Boolean |
Gives focus to the default-focus view in the view hierarchy that has this view as a root. |
| open Unit |
Schedules the layout animation to be played after the next layout pass of this view group. |
| open Unit |
setAddStatesFromChildren(addsStates: Boolean)Sets whether this ViewGroup's drawable states also include its children's drawable states. |
| open Unit |
setAlwaysDrawnWithCacheEnabled(always: Boolean)Indicates whether this ViewGroup will always try to draw its children using their drawing cache. |
| open Unit |
setAnimationCacheEnabled(enabled: Boolean)Enables or disables the children's drawing cache during a layout animation. |
| open Unit |
setClipChildren(clipChildren: Boolean)By default, children are clipped to their bounds before drawing. |
| open Unit |
setClipToPadding(clipToPadding: Boolean)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. |
| open Unit |
setDescendantFocusability(focusability: Int)Set the descendant focusability of this view group. |
| open Unit |
setLayoutAnimation(controller: LayoutAnimationController!)Sets the layout animation controller used to animate the group's children after the first layout. |
| open Unit |
setLayoutAnimationListener(animationListener: Animation.AnimationListener!)Specifies the animation listener to which layout animation events must be sent. |
| open Unit |
setLayoutMode(layoutMode: Int)Sets the basis of alignment during the layout of this ViewGroup. |
| open Unit |
setLayoutTransition(transition: LayoutTransition!)Sets the LayoutTransition object for this ViewGroup. |
| open Unit |
Enable or disable the splitting of MotionEvents to multiple children during touch event dispatch. |
| open Unit |
Register a callback to be invoked when a child is added to or removed from this view. |
| open Unit |
setPersistentDrawingCache(drawingCacheToKeep: Int)Indicates what types of drawing caches should be kept in memory after they have been created. |
| open Unit |
setRequestedFrameRate(frameRate: Float)You can set the preferred frame rate for a ViewGroup using a positive number or by specifying the preferred frame rate category using constants, including REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE, REQUESTED_FRAME_RATE_CATEGORY_LOW, REQUESTED_FRAME_RATE_CATEGORY_NORMAL, REQUESTED_FRAME_RATE_CATEGORY_HIGH. |
| open Unit |
setTouchscreenBlocksFocus(touchscreenBlocksFocus: Boolean)Set whether this ViewGroup should ignore focus requests for itself and its children. |
| open Unit |
setTransitionGroup(isTransitionGroup: Boolean)Changes whether or not this ViewGroup should be treated as a single entity during Activity Transitions. |
| open Unit |
Sets a |
| open Boolean |
Return true if the pressed state should be delayed for children or descendants of this ViewGroup. |
| open Boolean |
showContextMenuForChild(originalView: View!)Shows the context menu for the specified view or its ancestors. |
| open Boolean |
showContextMenuForChild(originalView: View!, x: Float, y: Float)Shows the context menu for the specified view or its ancestors anchored to the specified view-relative coordinate. |
| open ActionMode! |
startActionModeForChild(originalView: View!, callback: ActionMode.Callback!)Start an action mode for the specified view with the default type |
| open ActionMode! |
startActionModeForChild(originalView: View!, callback: ActionMode.Callback!, type: Int)Start an action mode of a specific type for the specified view. |
| open Unit |
Runs the layout animation. |
| open Unit |
startViewTransition(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. |
| open Unit |
suppressLayout(suppress: Boolean)Tells this ViewGroup to suppress all layout() calls until layout suppression is disabled with a later call to suppressLayout(false). |
| open Unit |
updateViewLayout(view: View!, params: ViewGroup.LayoutParams!) |
| Protected methods | |
|---|---|
| open Boolean |
addViewInLayout(child: View!, index: Int, params: ViewGroup.LayoutParams!)Adds a view during layout. |
| open Boolean |
addViewInLayout(child: View!, index: Int, params: ViewGroup.LayoutParams!, preventRequestLayout: Boolean)Adds a view during layout. |
| open Unit |
attachLayoutAnimationParameters(child: View!, params: ViewGroup.LayoutParams!, index: Int, count: Int)Subclasses should override this method to set layout animation parameters on the supplied child. |
| open Unit |
attachViewToParent(child: View!, index: Int, params: ViewGroup.LayoutParams!)Attaches a view to this view group. |
| open Boolean |
Indicates whether the view group has the ability to animate its children after the first layout. |
| open Boolean | |
| open Unit |
cleanupLayoutState(child: View!)Prevents the specified child to be laid out during the next layout pass. |
| open Unit | |
| open Unit |
Detaches all views from the parent. |
| open Unit |
detachViewFromParent(child: View!)Detaches a view from its parent. |
| open Unit |
detachViewFromParent(index: Int)Detaches a view from its parent. |
| open Unit |
detachViewsFromParent(start: Int, count: Int)Detaches a range of views from their parents. |
| open Unit |
dispatchDraw(canvas: Canvas)Called by draw to draw the child views. |
| open Unit |
dispatchFreezeSelfOnly(container: SparseArray<Parcelable!>!)Perform dispatching of a |
| open Boolean |
dispatchGenericFocusedEvent(event: MotionEvent!)Dispatch a generic motion event to the currently focused view. |
| open Boolean |
dispatchGenericPointerEvent(event: MotionEvent!)Dispatch a generic motion event to the view under the first pointer. |
| open Boolean |
dispatchHoverEvent(event: MotionEvent!)Dispatch a hover event. |
| open Unit |
dispatchRestoreInstanceState(container: SparseArray<Parcelable!>!)Called by |
| open Unit |
dispatchSaveInstanceState(container: SparseArray<Parcelable!>!)Called by |
| open Unit |
dispatchSetPressed(pressed: Boolean)Dispatch setPressed to all of this View's children. |
| open Unit |
dispatchThawSelfOnly(container: SparseArray<Parcelable!>!)Perform dispatching of a |
| open Unit |
dispatchVisibilityChanged(changedView: View, visibility: Int)Dispatch a view visibility change down the view hierarchy. |
| open Boolean |
Draw one child of this View Group. |
| open Unit |
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown. |
| open ViewGroup.LayoutParams! |
Returns a set of default layout parameters. |
| open ViewGroup.LayoutParams! |
Returns a safe set of layout parameters based on the supplied layout params. |
| open Int |
getChildDrawingOrder(childCount: Int, drawingPosition: Int)Converts drawing order position to container position. |
| open Boolean |
getChildStaticTransformation(child: View!, t: Transformation!)Sets |
| open Boolean |
Indicates whether the ViewGroup is drawing its children in the order defined by |
| open Boolean |
Indicates whether the ViewGroup is currently drawing its children using their drawing cache. |
| open Unit |
measureChild(child: View!, parentWidthMeasureSpec: Int, parentHeightMeasureSpec: Int)Ask one of the children of this view to measure itself, taking into account both the MeasureSpec requirements for this view and its padding. |
| open Unit |
measureChildWithMargins(child: View!, parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int)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. |
| open Unit |
measureChildren(widthMeasureSpec: Int, heightMeasureSpec: Int)Ask all of the children of this view to measure themselves, taking into account both the MeasureSpec requirements for this view and its padding. |
| open Unit |
This is called when the view is attached to a window. |
| open IntArray! |
onCreateDrawableState(extraSpace: Int)Generate the new |
| open Unit |
This is called when the view is detached from a window. |
| abstract Unit |
Called from layout when this view should assign a size and position to each of its children. |
| open Boolean |
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!)Look for a descendant to call android. |
| open Unit |
removeDetachedView(child: View!, animate: Boolean)Finishes the removal of a detached view. |
| open Unit |
setChildrenDrawingCacheEnabled(enabled: Boolean)Enables or disables the drawing cache for each child of this view group. |
| open Unit |
setChildrenDrawingOrderEnabled(enabled: Boolean)Tells the ViewGroup whether to draw its children in the order defined by the method |
| open Unit |
setChildrenDrawnWithCacheEnabled(enabled: Boolean)Tells the ViewGroup to draw its children using their drawing cache. |
| open Unit |
setStaticTransformationsEnabled(enabled: Boolean)When this property is set to true, this ViewGroup supports static transformations on children; this causes |
| Inherited functions | |
|---|---|
| Inherited properties | |
|---|---|
XML attributes
android:addStatesFromChildren
android:addStatesFromChildrenMay be a boolean value, such as "true" or "false".
android:alwaysDrawnWithCache
android:alwaysDrawnWithCacheMay be a boolean value, such as "true" or "false".
android:animateLayoutChanges
android:animateLayoutChangesMay be a boolean value, such as "true" or "false".
android:animationCache
android:animationCacheMay be a boolean value, such as "true" or "false".
android:clipChildren
android:clipChildrenMay be a boolean value, such as "true" or "false".
android:clipToPadding
android:clipToPaddingMay be a boolean value, such as "true" or "false".
android:descendantFocusability
android:descendantFocusabilityMust be one of the following constant values.
| Constant | Value | Description |
|---|---|---|
| afterDescendants | 1 | The ViewGroup will get focus only if none of its descendants want it. |
| beforeDescendants | 0 | The ViewGroup will get focus before any of its descendants. |
| blocksDescendants | 2 | The ViewGroup will block its descendants from receiving focus. |
android:layoutAnimation
android:layoutAnimationMay be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".
android:layoutMode
android:layoutModeMust be one of the following constant values.
| Constant | Value | Description |
|---|---|---|
| clipBounds | 0 | Use the children's clip bounds when laying out this container. |
| opticalBounds | 1 | Use the children's optical bounds when laying out this container. |
android:persistentDrawingCache
android:persistentDrawingCacheMust be one or more (separated by '|') of the following constant values.
| Constant | Value | Description |
|---|---|---|
| all | 3 | The drawing cache is always persisted. |
| animation | 1 | The drawing cache is persisted after a layout animation. |
| none | 0 | The drawing cache is not persisted after use. |
| scrolling | 2 | The drawing cache is persisted after a scroll. |
android:splitMotionEvents
android:splitMotionEventsandroid.view.ViewGroup#setMotionEventSplittingEnabled(boolean) for more information.
May be a boolean value, such as "true" or "false".
Constants
CLIP_TO_PADDING_MASK
protected static val CLIP_TO_PADDING_MASK: Int
We clip to padding when FLAG_CLIP_TO_PADDING and FLAG_PADDING_NOT_NULL are set at the same time.
Value: 34FOCUS_AFTER_DESCENDANTS
static val FOCUS_AFTER_DESCENDANTS: Int
This view will get focus only if none of its descendants want it.
Value: 262144FOCUS_BEFORE_DESCENDANTS
static val FOCUS_BEFORE_DESCENDANTS: Int
This view will get focus before any of its descendants.
Value: 131072FOCUS_BLOCK_DESCENDANTS
static val FOCUS_BLOCK_DESCENDANTS: Int
This view will block any of its descendants from getting focus, even if they are focusable.
Value: 393216LAYOUT_MODE_CLIP_BOUNDS
static val LAYOUT_MODE_CLIP_BOUNDS: Int
This constant is a layoutMode. Clip bounds are the raw values of left, top, right and bottom.
Value: 0LAYOUT_MODE_OPTICAL_BOUNDS
static val LAYOUT_MODE_OPTICAL_BOUNDS: Int
This constant is a layoutMode. Optical bounds describe where a widget appears to be. They sit inside the clip bounds which need to cover a larger area to allow other effects, such as shadows and glows, to be drawn.
Value: 1PERSISTENT_ALL_CACHES
static valPERSISTENT_ALL_CACHES: Int
Deprecated: The view drawing cache was largely made obsolete with the introduction of hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache layers are largely unnecessary and can easily result in a net loss in performance due to the cost of creating and updating the layer. In the rare cases where caching layers are useful, such as for alpha animations, setLayerType(int,android.graphics.Paint) handles this with hardware rendering. For software-rendered snapshots of a small part of the View hierarchy or individual Views it is recommended to create a Canvas from either a Bitmap or android.graphics.Picture and call draw(android.graphics.Canvas) on the View. However these software-rendered usages are discouraged and have compatibility issues with hardware-only rendering features such as Config.HARDWARE bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback reports or unit testing the PixelCopy API is recommended.
Used to indicate that all drawing caches should be kept in memory.
Value: 3PERSISTENT_ANIMATION_CACHE
static valPERSISTENT_ANIMATION_CACHE: Int
Deprecated: The view drawing cache was largely made obsolete with the introduction of hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache layers are largely unnecessary and can easily result in a net loss in performance due to the cost of creating and updating the layer. In the rare cases where caching layers are useful, such as for alpha animations, setLayerType(int,android.graphics.Paint) handles this with hardware rendering. For software-rendered snapshots of a small part of the View hierarchy or individual Views it is recommended to create a Canvas from either a Bitmap or android.graphics.Picture and call draw(android.graphics.Canvas) on the View. However these software-rendered usages are discouraged and have compatibility issues with hardware-only rendering features such as Config.HARDWARE bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback reports or unit testing the PixelCopy API is recommended.
Used to indicate that the animation drawing cache should be kept in memory.
Value: 1PERSISTENT_NO_CACHE
static valPERSISTENT_NO_CACHE: Int
Deprecated: The view drawing cache was largely made obsolete with the introduction of hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache layers are largely unnecessary and can easily result in a net loss in performance due to the cost of creating and updating the layer. In the rare cases where caching layers are useful, such as for alpha animations, setLayerType(int,android.graphics.Paint) handles this with hardware rendering. For software-rendered snapshots of a small part of the View hierarchy or individual Views it is recommended to create a Canvas from either a Bitmap or android.graphics.Picture and call draw(android.graphics.Canvas) on the View. However these software-rendered usages are discouraged and have compatibility issues with hardware-only rendering features such as Config.HARDWARE bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback reports or unit testing the PixelCopy API is recommended.
Used to indicate that no drawing cache should be kept in memory.
Value: 0PERSISTENT_SCROLLING_CACHE
static valPERSISTENT_SCROLLING_CACHE: Int
Deprecated: The view drawing cache was largely made obsolete with the introduction of hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache layers are largely unnecessary and can easily result in a net loss in performance due to the cost of creating and updating the layer. In the rare cases where caching layers are useful, such as for alpha animations, setLayerType(int,android.graphics.Paint) handles this with hardware rendering. For software-rendered snapshots of a small part of the View hierarchy or individual Views it is recommended to create a Canvas from either a Bitmap or android.graphics.Picture and call draw(android.graphics.Canvas) on the View. However these software-rendered usages are discouraged and have compatibility issues with hardware-only rendering features such as Config.HARDWARE bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback reports or unit testing the PixelCopy API is recommended.
Used to indicate that the scrolling drawing cache should be kept in memory.
Value: 2Public constructors
ViewGroup
ViewGroup(
context: Context!,
attrs: AttributeSet!,
defStyleAttr: Int)
ViewGroup
ViewGroup(
context: Context!,
attrs: AttributeSet!,
defStyleAttr: Int,
defStyleRes: Int)
Public methods
addChildrenForAccessibility
open fun addChildrenForAccessibility(outChildren: ArrayList<View!>!): Unit
Adds the children of this View relevant for accessibility to the given list as output. Since some Views are not important for accessibility the added child views are not necessarily direct children of this view, rather they are the first level of descendants important for accessibility.
| Parameters | |
|---|---|
outChildren |
ArrayList<View!>!: The output list that will receive children for accessibility. |
addExtraDataToAccessibilityNodeInfo
open fun addExtraDataToAccessibilityNodeInfo(
info: AccessibilityNodeInfo,
extraDataKey: String,
arguments: Bundle?
): Unit
Adds extra data to an AccessibilityNodeInfo based on an explicit request for the additional data.
This method only needs overloading if the node is marked as having extra data available.
.If you override this method you must call through to the superclass implementation.
| Parameters | |
|---|---|
info |
AccessibilityNodeInfo: The info to which to add the extra data. Never null. |
extraDataKey |
String: A key specifying the type of extra data to add to the info. The extra data should be added to the Bundle returned by the info's AccessibilityNodeInfo.getExtras method. Never null. |
arguments |
Bundle?: A Bundle holding any arguments relevant for this request. May be null if the service provided no arguments. |
addFocusables
open fun addFocusables(
views: ArrayList<View!>!,
direction: Int,
focusableMode: Int
): Unit
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.
| Parameters | |
|---|---|
views |
ArrayList<View!>!: Focusable views found so far or null if all we are interested is the number of focusables. |
direction |
Int: The direction of the focus. Value is one of the following: |
focusableMode |
Int: The type of focusables to be added. Value is either 0 or a combination of the following:
|
addKeyboardNavigationClusters
open fun addKeyboardNavigationClusters(
: MutableCollection<View!>,
: Int
): Unit
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.
| Parameters | |
|---|---|
views |
MutableCollection<View!>: Keyboard navigation cluster roots found so far. This value cannot be null. |
direction |
Int: Direction to look |
addStatesFromChildren
open fun addStatesFromChildren(): Boolean
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.
addTouchables
open fun addTouchables(views: ArrayList<View!>!): Unit
Add any touchable views that are descendants of this view (possibly including this view if it is touchable itself) to views.
| Parameters | |
|---|---|
views |
ArrayList<View!>!: Touchable views found so far |
addView
open fun addView(child: View!): Unit
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 draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
| Parameters | |
|---|---|
child |
View!: the child view to add |
See Also
addView
open fun addView(
child: View!,
params: ViewGroup.LayoutParams!
): Unit
Adds a child view with the specified layout parameters.
Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
| Parameters | |
|---|---|
view |
The view to be added to this window. |
params |
ViewGroup.LayoutParams!: the layout parameters to set on the child |
child |
View!: the child view to add |
addView
open fun addView(
child: View!,
index: Int
): Unit
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 draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
| Parameters | |
|---|---|
child |
View!: the child view to add |
index |
Int: the position at which to add the child |
See Also
addView
open fun addView(
child: View!,
index: Int,
params: ViewGroup.LayoutParams!
): Unit
Adds a child view with the specified layout parameters.
Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
| Parameters | |
|---|---|
child |
View!: the child view to add |
index |
Int: the position at which to add the child or -1 to add last |
params |
ViewGroup.LayoutParams!: the layout parameters to set on the child |
addView
open fun addView(
child: View!,
width: Int,
height: Int
): Unit
Adds a child view with this ViewGroup's default layout parameters and the specified width and height.
Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
| Parameters | |
|---|---|
child |
View!: the child view to add |
bringChildToFront
open fun bringChildToFront(child: View!): Unit
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). Prior to android.os.Build.VERSION_CODES#KITKAT this method should be followed by calls to requestLayout() and View.invalidate() on this parent to force the parent to redraw with the new child ordering.
| Parameters | |
|---|---|
child |
View!: The child to bring to the top of the z order |
childDrawableStateChanged
open fun childDrawableStateChanged(child: View): Unit
If addStatesFromChildren is true, refreshes this group's drawable state (to include the states from its children).
| Parameters | |
|---|---|
child |
View: The child whose drawable state has changed. This value cannot be null. |
childHasTransientStateChanged
open fun childHasTransientStateChanged(
child: View,
childHasTransientState: Boolean
): Unit
Called when a child view has changed whether or not it is tracking transient state.
| Parameters | |
|---|---|
child |
View: Child view whose state has changed. This value cannot be null. |
hasTransientState |
true if this child has transient state |
clearChildFocus
open fun clearChildFocus(child: View!): Unit
Called when a child of this parent is giving up focus
| Parameters | |
|---|---|
child |
View!: The view that is giving up focus |
clearDisappearingChildren
open fun clearDisappearingChildren(): Unit
Removes any pending animations for views that have been removed. Call this if you don't want animations for exiting views to stack up.
clearFocus
open fun clearFocus(): Unit
Called when this view wants to give up focus. If focus is cleared onFocusChanged(boolean,int,android.graphics.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.
dispatchApplyWindowInsets
open fun dispatchApplyWindowInsets(insets: WindowInsets!): WindowInsets!
Request to apply the given window insets to this view or another view in its subtree.
This method should be called by clients wishing to apply insets corresponding to areas obscured by window decorations or overlays. This can include the status and navigation bars, action bars, input methods and more. New inset categories may be added in the future. The method returns the insets provided minus any that were applied by this view or its children.
Clients wishing to provide custom behavior should override the onApplyWindowInsets(android.view.WindowInsets) method or alternatively provide a OnApplyWindowInsetsListener via the setOnApplyWindowInsetsListener method.
This method replaces the older fitSystemWindows method.
| Parameters | |
|---|---|
insets |
WindowInsets!: Insets to apply |
| Return | |
|---|---|
WindowInsets! |
The provided insets minus the insets that were consumed |
dispatchCapturedPointerEvent
open fun dispatchCapturedPointerEvent(event: MotionEvent!): Boolean
Pass a captured pointer event down to the focused view.
| Parameters | |
|---|---|
event |
MotionEvent!: The motion event to be dispatched. |
| Return | |
|---|---|
Boolean |
True if the event was handled by the view, false otherwise. |
dispatchConfigurationChanged
open fun dispatchConfigurationChanged(newConfig: Configuration!): Unit
Dispatch a notification about a resource configuration change down the view hierarchy. ViewGroups should override to route to their children.
| Parameters | |
|---|---|
newConfig |
Configuration!: The new resource configuration. |
dispatchCreateViewTranslationRequest
open fun dispatchCreateViewTranslationRequest(
viewIds: MutableMap<AutofillId!, LongArray!>,
supportedFormats: IntArray,
capability: TranslationCapability!,
requests: MutableList<ViewTranslationRequest!>
): Unit
Dispatch to collect the ViewTranslationRequests for translation purpose by traversing the hierarchy when the app requests ui translation. Typically, this method should only be overridden by subclasses that provide a view hierarchy (such as ViewGroup). Other classes should override View.onCreateViewTranslationRequest for normal view or override View.onVirtualViewTranslationResponses for view contains virtual children. When requested to start the ui translation, the system will call this method to traverse the view hierarchy to collect ViewTranslationRequests and create a android.view.translation.Translator to translate the requests. All the ViewTranslationRequests must be added when the traversal is done.
The default implementation calls View.onCreateViewTranslationRequest for normal view or calls View.onVirtualViewTranslationResponses for view contains virtual children to build ViewTranslationRequest if the view should be translated. The view is marked as having transient state so that recycling of views doesn't prevent the system from attaching the response to it. Therefore, if overriding this method, you should set or reset the transient state.
dispatchCreateViewTranslationRequest for all the child views.
| Parameters | |
|---|---|
viewIds |
MutableMap<AutofillId!, LongArray!>: This value cannot be null. |
supportedFormats |
IntArray: This value cannot be null. Value is one of the following: |
capability |
TranslationCapability!: This value may be null. |
requests |
MutableList<ViewTranslationRequest!>: This value cannot be null. |
dispatchDisplayHint
open fun dispatchDisplayHint(hint: Int): Unit
Dispatch a hint about whether this view is displayed. For instance, when a View moves out of the screen, it might receives a display hint indicating the view is not displayed. Applications should not rely on this hint as there is no guarantee that they will receive one.
| Parameters | |
|---|---|
hint |
Int: A hint about whether or not this view is displayed: VISIBLE or INVISIBLE. Value is one of the following: |
dispatchDragEvent
open fun dispatchDragEvent(event: DragEvent!): Boolean
Detects if this View is enabled and has a drag event listener. If both are true, then it calls the drag event listener with the android.view.DragEvent it received. If the drag event listener returns true, then dispatchDragEvent() returns true.
For all other cases, the method calls the onDragEvent() drag event handler method and returns its result.
This ensures that a drag event is always consumed, even if the View does not have a drag event listener. However, if the View has a listener and the listener returns true, then onDragEvent() is not called.
dispatchDrawableHotspotChanged
open fun dispatchDrawableHotspotChanged(
x: Float,
y: Float
): Unit
Dispatches drawable hotspot changes to child views that meet at least one of the following criteria:
- Returns
falsefrom bothView.isClickable()andView.isLongClickable() - Requests duplication of parent state via
View.setDuplicateParentStateEnabled(boolean)
| Parameters | |
|---|---|
x |
Float: hotspot x coordinate |
y |
Float: hotspot y coordinate |
dispatchFinishTemporaryDetach
open fun dispatchFinishTemporaryDetach(): Unit
Dispatch onFinishTemporaryDetach() to this View and its direct children if this is a container View.
If you override this method you must call through to the superclass implementation.
dispatchKeyEvent
open fun dispatchKeyEvent(event: KeyEvent!): Boolean
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.
| Parameters | |
|---|---|
event |
KeyEvent!: The key event to be dispatched. |
| Return | |
|---|---|
Boolean |
True if the event was handled, false otherwise. |
dispatchKeyEventPreIme
open fun dispatchKeyEventPreIme(event: KeyEvent!): Boolean
Dispatch a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application's UI instead of allowing the IME to see it and close itself.
| Parameters | |
|---|---|
event |
KeyEvent!: The key event to be dispatched. |
| Return | |
|---|---|
Boolean |
True if the event was handled, false otherwise. |
dispatchKeyShortcutEvent
open fun dispatchKeyShortcutEvent(event: KeyEvent!): Boolean
Dispatches a key shortcut event.
| Parameters | |
|---|---|
event |
KeyEvent!: The key event to be dispatched. |
| Return | |
|---|---|
Boolean |
True if the event was handled by the view, false otherwise. |
dispatchPointerCaptureChanged
open fun dispatchPointerCaptureChanged(hasCapture: Boolean): Unit
dispatchProvideAutofillStructure
open fun dispatchProvideAutofillStructure(
structure: ViewStructure,
flags: Int
): Unit
Dispatches creation of a ViewStructures for autofill purposes down the hierarchy, when an Assist structure is being created as part of an autofill request.
The default implementation does the following:
- Sets the
AutofillIdin the structure. - Calls
onProvideAutofillStructure(android.view.ViewStructure,int). - Calls
onProvideAutofillVirtualStructure(android.view.ViewStructure,int).
Typically, this method should only be overridden by subclasses that provide a view hierarchy (such as ViewGroup) - other classes should override onProvideAutofillStructure(android.view.ViewStructure,int) or onProvideAutofillVirtualStructure(android.view.ViewStructure,int) instead.
When overridden, it must:
- Either call
super.dispatchProvideAutofillStructure(structure, flags)or explicitly set theAutofillIdin the structure (for example, by callingstructure.setAutofillId(getAutofillId())). - Decide how to handle the
AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWSflag - when set, all views in the structure should be considered important for autofill, regardless of whatisImportantForAutofill()returns. We encourage you to respect this flag to provide a better user experience - this flag is typically used when an user explicitly requested autofill. If the flag is not set, then only views marked as important for autofill should be included in the structure - skipping non-important views optimizes the overall autofill performance.
This implementation adds in all child views of the view group, in addition to calling the default View implementation.
| Parameters | |
|---|---|
structure |
ViewStructure: fill in with structured view data for autofill purposes. This value cannot be null. |
flags |
Int: Value is either 0 or
|
dispatchProvideStructure
open fun dispatchProvideStructure(structure: ViewStructure!): Unit
Dispatch creation of ViewStructure down the hierarchy. This implementation adds in all child views of the view group, in addition to calling the default View implementation.
dispatchScrollCaptureSearch
open fun dispatchScrollCaptureSearch(
localVisibleRect: Rect,
windowOffset: Point,
targets: Consumer<ScrollCaptureTarget!>
): Unit
Handle the scroll capture search request by checking this view if applicable, then to each child view.
| Parameters | |
|---|---|
localVisibleRect |
Rect: the visible area of this ViewGroup in local coordinates, according to the parent. This value cannot be null. |
windowOffset |
Point: the offset of this view within the window. This value cannot be null. |
targets |
Consumer<ScrollCaptureTarget!>: accepts potential scroll capture targets; results.accept may be called zero or more times on the calling thread before onScrollCaptureSearch returns. This value cannot be null. |
dispatchSetActivated
open fun dispatchSetActivated(activated: Boolean): Unit
Dispatch setActivated to all of this View's children.
| Parameters | |
|---|---|
activated |
Boolean: The new activated state |
dispatchSetSelected
open fun dispatchSetSelected(selected: Boolean): Unit
Dispatch setSelected to all of this View's children.
| Parameters | |
|---|---|
selected |
Boolean: The new selected state |
dispatchStartTemporaryDetach
open fun dispatchStartTemporaryDetach(): Unit
Dispatch onStartTemporaryDetach() to this View and its direct children if this is a container View.
If you override this method you must call through to the superclass implementation.
dispatchSystemUiVisibilityChanged
open fundispatchSystemUiVisibilityChanged(visible: Int): Unit
Deprecated: Deprecated in Java.
Dispatch callbacks to setOnSystemUiVisibilityChangeListener down the view hierarchy.
dispatchTouchEvent
open fun dispatchTouchEvent(ev: MotionEvent!): Boolean
Pass the touch screen motion event down to the target view, or this view if it is the target.
| Parameters | |
|---|---|
event |
The motion event to be dispatched. |
| Return | |
|---|---|
Boolean |
True if the event was handled by the view, false otherwise. |
dispatchTrackballEvent
open fun dispatchTrackballEvent(event: MotionEvent!): Boolean
Pass a trackball motion event down to the focused view.
| Parameters | |
|---|---|
event |
MotionEvent!: The motion event to be dispatched. |
| Return | |
|---|---|
Boolean |
True if the event was handled by the view, false otherwise. |
dispatchUnhandledMove
open fun dispatchUnhandledMove(
focused: View!,
direction: Int
): Boolean
This method is the last chance for the focused view and its ancestors to respond to an arrow key. This is called when the focused view did not consume the key internally, nor could the view system find a new view in the requested direction to give focus to.
| Parameters | |
|---|---|
focused |
View!: The currently focused view. |
direction |
Int: The direction focus wants to move. One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. Value is one of the following: |
| Return | |
|---|---|
Boolean |
True if the this view consumed this unhandled move. |
dispatchWindowFocusChanged
open fun dispatchWindowFocusChanged(hasFocus: Boolean): Unit
Called when the window containing this view gains or loses window focus. ViewGroups should override to route to their children.
| Parameters | |
|---|---|
hasFocus |
Boolean: True if the window containing this view now has focus, false otherwise. |
dispatchWindowInsetsAnimationEnd
open fun dispatchWindowInsetsAnimationEnd(animation: WindowInsetsAnimation): Unit
Dispatches WindowInsetsAnimation.Callback.onEnd(WindowInsetsAnimation) when Window Insets animation ends.
| Parameters | |
|---|---|
animation |
WindowInsetsAnimation: This value cannot be null. |
dispatchWindowInsetsAnimationPrepare
open fun dispatchWindowInsetsAnimationPrepare(animation: WindowInsetsAnimation): Unit
Dispatches WindowInsetsAnimation.Callback.onPrepare(WindowInsetsAnimation) when Window Insets animation is being prepared.
| Parameters | |
|---|---|
animation |
WindowInsetsAnimation: This value cannot be null. |
dispatchWindowInsetsAnimationProgress
open fun dispatchWindowInsetsAnimationProgress(
insets: WindowInsets,
runningAnimations: MutableList<WindowInsetsAnimation!>
): WindowInsets
Dispatches WindowInsetsAnimation.Callback.onProgress(WindowInsets, List) when Window Insets animation makes progress.
| Parameters | |
|---|---|
insets |
WindowInsets: This value cannot be null. |
runningAnimations |
MutableList<WindowInsetsAnimation!>: This value cannot be null. |
| Return | |
|---|---|
WindowInsets |
This value cannot be null. |
dispatchWindowInsetsAnimationStart
open fun dispatchWindowInsetsAnimationStart(
animation: WindowInsetsAnimation,
bounds: WindowInsetsAnimation.Bounds
): WindowInsetsAnimation.Bounds
Dispatches WindowInsetsAnimation.Callback.onStart(WindowInsetsAnimation, Bounds) when Window Insets animation is started.
| Parameters | |
|---|---|
animation |
WindowInsetsAnimation: This value cannot be null. |
bounds |
WindowInsetsAnimation.Bounds: This value cannot be null. |
| Return | |
|---|---|
WindowInsetsAnimation.Bounds |
This value cannot be null. |
dispatchWindowSystemUiVisiblityChanged
open fundispatchWindowSystemUiVisiblityChanged(visible: Int): Unit
Deprecated: Deprecated in Java.
Dispatch callbacks to onWindowSystemUiVisibilityChanged(int) down the view hierarchy.
dispatchWindowVisibilityChanged
open fun dispatchWindowVisibilityChanged(visibility: Int): Unit
Dispatch a window visibility change down the view hierarchy. ViewGroups should override to route to their children.
| Parameters | |
|---|---|
visibility |
Int: The new visibility of the window. Value is one of the following: |
endViewTransition
open fun endViewTransition(view: View!): Unit
This method should always be called following an earlier call to startViewTransition(android.view.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.
| Return | |
|---|---|
Unit |
view The View object that has been removed but is being kept around in the visible hierarchy by an earlier call to startViewTransition(android.view.View). |
findFocus
open fun findFocus(): View!
Find the view in the hierarchy rooted at this view that currently has focus.
| Return | |
|---|---|
View! |
The view that currently has focus, or null if no focused view can be found. |
findOnBackInvokedDispatcherForChild
open fun findOnBackInvokedDispatcherForChild(
child: View,
requester: View
): OnBackInvokedDispatcher?
Walk up the View hierarchy to find the nearest OnBackInvokedDispatcher.
| Parameters | |
|---|---|
child |
View: The direct child of this view for which to find a dispatcher. This value cannot be null. |
requester |
View: The requester that will use the dispatcher. Can be the same as child. This value cannot be null. |
| Return | |
|---|---|
OnBackInvokedDispatcher? |
The OnBackInvokedDispatcher from this or the nearest ancestor, or null if the view is both not attached and have no ancestor providing an OnBackInvokedDispatcher. |
findViewsWithText
open fun findViewsWithText(
outViews: ArrayList<View!>!,
text: CharSequence!,
flags: Int
): Unit
Finds the Views that contain given text. The containment is case insensitive. The search is performed by either the text that the View renders or the content description that describes the view for accessibility purposes and the view does not render or both. Clients can specify how the search is to be performed via passing the FIND_VIEWS_WITH_TEXT and FIND_VIEWS_WITH_CONTENT_DESCRIPTION flags.
| Parameters | |
|---|---|
outViews |
ArrayList<View!>!: The output list of matching Views. |
searched |
The text to match against. |
flags |
Int: Value is either 0 or a combination of the following:
|
focusSearch
open fun focusSearch(
focused: View!,
direction: Int
): View!
Find the nearest view in the specified direction that wants to take focus.
| Parameters | |
|---|---|
v |
The view that currently has focus |
direction |
Int: One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT, or 0 for not applicable. |
focused |
View!: The view that currently has focus |
focusableViewAvailable
open fun focusableViewAvailable(v: View!): Unit
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 |
View!: The view that has become newly focusable |
gatherTransparentRegion
open fun gatherTransparentRegion(region: Region?): Boolean
This is used by the ViewRoot to perform an optimization when the view hierarchy contains one or several SurfaceView. SurfaceView is always considered transparent, but its children are not, therefore all View objects remove themselves from the global transparent region (passed as a parameter to this function).
| Parameters | |
|---|---|
region |
Region?: The transparent region for this ViewAncestor (window). This value may be null. |
| Return | |
|---|---|
Boolean |
Returns true if the effective visibility of the view at this point is opaque, regardless of the transparent region; returns false if it is possible for underlying windows to be seen behind the view. |
generateLayoutParams
open fun generateLayoutParams(attrs: AttributeSet!): ViewGroup.LayoutParams!
Returns a new set of layout parameters based on the supplied attributes set.
| Parameters | |
|---|---|
attrs |
AttributeSet!: the attributes to build the layout parameters from |
| Return | |
|---|---|
ViewGroup.LayoutParams! |
an instance of android.view.ViewGroup.LayoutParams or one of its descendants |
getAccessibilityClassName
open fun getAccessibilityClassName(): CharSequence!
Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.
getChildAt
open fun getChildAt(index: Int): View!
Returns the view at the specified position in the group.
| Parameters | |
|---|---|
index |
Int: the position at which to get the view from |
| Return | |
|---|---|
View! |
the view at the specified position or null if the position does not exist within the group |
getChildCount
open fun getChildCount(): Int
Returns the number of children in the group.
| Return | |
|---|---|
Int |
a positive integer representing the number of children in the group |
getChildDrawingOrder
fun getChildDrawingOrder(drawingPosition: Int): Int
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 |
Int: the drawing order position. |
| Return | |
|---|---|
Int |
the container position of a child for this drawing order position. |
See Also
getChildMeasureSpec
open static fun getChildMeasureSpec(
spec: Int,
padding: Int,
childDimension: Int
): Int
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 |
Int: The requirements for this view |
padding |
Int: The padding of this view for the current dimension and margins, if applicable |
childDimension |
Int: How big the child wants to be in the current dimension |
| Return | |
|---|---|
Int |
a MeasureSpec integer for the child |
getChildVisibleRect
open fun getChildVisibleRect(
child: View!,
r: Rect!,
offset: Point!
): Boolean
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 |
View!: A child View, whose rectangular visible region we want to compute |
r |
Rect!: The input rectangle, defined in the child coordinate system. Will be overwritten to contain the resulting visible rectangle, expressed in global (root) coordinates |
offset |
Point!: 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) |
| Return | |
|---|---|
Boolean |
true if the resulting rectangle is not empty, false otherwise |
getClipChildren
open fun getClipChildren(): Boolean
Returns whether this group's children are clipped to their bounds before drawing. The default value is true.
| Return | |
|---|---|
Boolean |
True if the group's children will be clipped to their bounds, false otherwise. |
See Also
getClipToPadding
open fun getClipToPadding(): Boolean
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.
| Return | |
|---|---|
Boolean |
true if this ViewGroup clips children to its padding and resizes (but doesn't clip) any EdgeEffect to the padded region, false otherwise. |
getDescendantFocusability
open fun getDescendantFocusability(): Int
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 requestFocus(int,android.graphics.Rect).
| Return | |
|---|---|
Int |
one of FOCUS_BEFORE_DESCENDANTS, FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS. |
getFocusedChild
open fun getFocusedChild(): View!
Returns the focused child of this view, if any. The child may have focus or contain focus.
| Return | |
|---|---|
View! |
the focused child or null. |
getLayoutAnimation
open fun getLayoutAnimation(): LayoutAnimationController!
Returns the layout animation controller used to animate the group's children.
| Return | |
|---|---|
LayoutAnimationController! |
the current animation controller |
getLayoutAnimationListener
open fun getLayoutAnimationListener(): Animation.AnimationListener!
Returns the animation listener to which layout animation events are sent.
| Return | |
|---|---|
Animation.AnimationListener! |
an android.view.animation.Animation.AnimationListener |
getLayoutMode
open fun getLayoutMode(): Int
Returns the basis of alignment during layout operations on this ViewGroup: either LAYOUT_MODE_CLIP_BOUNDS or LAYOUT_MODE_OPTICAL_BOUNDS.
If no layoutMode was explicitly set, either programmatically or in an XML resource, the method returns the layoutMode of the view's parent ViewGroup if such a parent exists, otherwise the method returns a default value of LAYOUT_MODE_CLIP_BOUNDS.
| Return | |
|---|---|
Int |
the layout mode to use during layout operations |
See Also
getLayoutTransition
open fun getLayoutTransition(): LayoutTransition!
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).
| Return | |
|---|---|
LayoutTransition! |
LayoutTranstion The LayoutTransition object that will animated changes in layout. A value of null means no transition will run on layout changes. |
getNestedScrollAxes
open fun getNestedScrollAxes(): Int
Return the current axes of nested scrolling for this ViewGroup.
A ViewGroup returning something other than SCROLL_AXIS_NONE is currently acting as a nested scrolling parent for one or more descendant views in the hierarchy.
| Return | |
|---|---|
Int |
Flags indicating the current axes of nested scrolling |
getOverlay
open fun getOverlay(): ViewGroupOverlay!
Returns the ViewGroupOverlay for this view group, creating it if it does not yet exist. In addition to ViewOverlay's support for drawables, ViewGroupOverlay allows views to be added to the overlay. These views, like overlay drawables, are visual-only; they do not receive input events and should not be used as anything other than a temporary representation of a view in a parent container, such as might be used by an animation effect.
Note: Overlays do not currently work correctly with SurfaceView or TextureView; contents in overlays for these types of views may not display correctly.
| Return | |
|---|---|
ViewGroupOverlay! |
The ViewGroupOverlay object for this view. |
See Also
getPersistentDrawingCache
open fungetPersistentDrawingCache(): Int
Deprecated: The view drawing cache was largely made obsolete with the introduction of hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache layers are largely unnecessary and can easily result in a net loss in performance due to the cost of creating and updating the layer. In the rare cases where caching layers are useful, such as for alpha animations, setLayerType(int,android.graphics.Paint) handles this with hardware rendering. For software-rendered snapshots of a small part of the View hierarchy or individual Views it is recommended to create a Canvas from either a Bitmap or android.graphics.Picture and call draw(android.graphics.Canvas) on the View. However these software-rendered usages are discouraged and have compatibility issues with hardware-only rendering features such as Config.HARDWARE bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback reports or unit testing the PixelCopy API is recommended.
Returns an integer indicating what types of drawing caches are kept in memory.
| Return | |
|---|---|
Int |
one or a combination of PERSISTENT_NO_CACHE, PERSISTENT_ANIMATION_CACHE, PERSISTENT_SCROLLING_CACHE and PERSISTENT_ALL_CACHES |
getTouchscreenBlocksFocus
open fun getTouchscreenBlocksFocus(): Boolean
Check whether this ViewGroup should ignore focus requests for itself and its children.
hasFocus
open fun hasFocus(): Boolean
Returns true if this view has or contains focus
| Return | |
|---|---|
Boolean |
true if this view has or contains focus |
hasTransientState
open fun hasTransientState(): Boolean
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.
| Return | |
|---|---|
Boolean |
true if the view has transient state |
indexOfChild
open fun indexOfChild(child: View!): Int
Returns the position in the group of the specified child view.
| Parameters | |
|---|---|
child |
View!: the view for which to get the position |
| Return | |
|---|---|
Int |
a positive integer representing the position of the view in the group, or -1 if the view does not exist in the group |
invalidateChild
funinvalidateChild(
child: View!,
dirty: Rect!
): Unit
Deprecated: Use onDescendantInvalidated(android.view.View,android.view.View) instead to observe updates to draw state in descendants.
Don't call or override this method. It is used for the implementation of the view hierarchy.
| Parameters | |
|---|---|
child |
View!: The child which is dirty |
r |
The area within the child that is invalid |
invalidateChildInParent
open funinvalidateChildInParent(
location: IntArray!,
dirty: Rect!
): ViewParent!
Deprecated: Use onDescendantInvalidated(android.view.View,android.view.View) instead to observe updates to draw state in descendants.
Don't call or override this method. It is used for the implementation of the view hierarchy. This implementation returns null if this ViewGroup does not have a parent, if this ViewGroup is already fully invalidated or if the dirty rectangle does not intersect with this ViewGroup's bounds.
| Parameters | |
|---|---|
location |
IntArray!: 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 |
| Return | |
|---|---|
ViewParent! |
the parent of this ViewParent or null |
isAlwaysDrawnWithCacheEnabled
open funisAlwaysDrawnWithCacheEnabled(): Boolean
Deprecated: As of android.os.Build.VERSION_CODES#M, this property is ignored. Child views may no longer have their caching behavior disabled by parents.
Indicates whether this ViewGroup will always try to draw its children using their drawing cache. By default this property is enabled.
| Return | |
|---|---|
Boolean |
true if the animation cache is enabled, false otherwise |
isAnimationCacheEnabled
open funisAnimationCacheEnabled(): Boolean
Deprecated: As of android.os.Build.VERSION_CODES#M, this property is ignored. Caching behavior of children may be controlled through View.setLayerType(int, Paint).
Indicates whether the children's drawing cache is used during a layout animation. By default, the drawing cache is enabled but this will prevent nested layout animations from working. To nest animations, you must disable the cache.
| Return | |
|---|---|
Boolean |
true if the animation cache is enabled, false otherwise |
isLayoutSuppressed
open fun isLayoutSuppressed(): Boolean
Returns whether layout calls on this container are currently being suppressed, due to an earlier call to suppressLayout(boolean).
| Return | |
|---|---|
Boolean |
true if layout calls are currently suppressed, false otherwise. |
isMotionEventSplittingEnabled
open fun isMotionEventSplittingEnabled(): Boolean
Returns true if MotionEvents dispatched to this ViewGroup can be split to multiple children.
| Return | |
|---|---|
Boolean |
true if MotionEvents dispatched to this ViewGroup can be split to multiple children. |
isTransitionGroup
open fun isTransitionGroup(): Boolean
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.
| Return | |
|---|---|
Boolean |
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 getTransitionName() is not null or if a non-null android.view.ViewOutlineProvider other than android.view.ViewOutlineProvider#BACKGROUND was given to setOutlineProvider(android.view.ViewOutlineProvider) and false otherwise. |
jumpDrawablesToCurrentState
open fun jumpDrawablesToCurrentState(): Unit
Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.
Also calls StateListAnimator.jumpToCurrentState() if there is a StateListAnimator attached to this view.
If you override this method you must call through to the superclass implementation.
layout
fun layout(
l: Int,
t: Int,
r: Int,
b: Int
): Unit
Assign a size and position to a view and all of its descendants
This is the second phase of the layout mechanism. (The first is measuring). In this phase, each parent calls layout on all of its children to position them. This is typically done using the child measurements that were stored in the measure pass().
Derived classes should not override this method. Derived classes with children should override onLayout. In that method, they should call layout on each of their children.
| Parameters | |
|---|---|
l |
Int: Left position, relative to parent |
t |
Int: Top position, relative to parent |
r |
Int: Right position, relative to parent |
b |
Int: Bottom position, relative to parent |
notifySubtreeAccessibilityStateChanged
open fun notifySubtreeAccessibilityStateChanged(
child: View,
source: View,
changeType: Int
): Unit
Notifies a view parent that the accessibility state of one of its descendants has changed and that the structure of the subtree is different.
| Parameters | |
|---|---|
child |
View: The direct child whose subtree has changed. This value cannot be null. |
source |
View: The descendant view that changed. May not be null. |
changeType |
Int: A bit mask of the types of changes that occurred. One or more of:
|
offsetDescendantRectToMyCoords
fun offsetDescendantRectToMyCoords(
descendant: View!,
rect: Rect!
): Unit
Offset a rectangle that is in a descendant's coordinate space into our coordinate space.
| Parameters | |
|---|---|
descendant |
View!: A descendant of this view |
rect |
Rect!: A rectangle defined in descendant's coordinate space. |
offsetRectIntoDescendantCoords
fun offsetRectIntoDescendantCoords(
descendant: View!,
rect: Rect!
): Unit
Offset a rectangle that is in our coordinate space into an ancestor's coordinate space.
| Parameters | |
|---|---|
descendant |
View!: A descendant of this view |
rect |
Rect!: A rectangle defined in descendant's coordinate space. |
onDescendantInvalidated
open fun onDescendantInvalidated(
child: View,
target: View
): Unit
The target View has been invalidated, or has had a drawing property changed that requires the hierarchy to re-render. This method is called by the View hierarchy to signal ancestors that a View either needs to re-record its drawing commands, or drawing properties have changed. This is how Views schedule a drawing traversal. This signal is generally only dispatched for attached Views, since only they need to draw. If you override this method you must call through to the superclass implementation.
| Parameters | |
|---|---|
child |
View: This value cannot be null. |
target |
View: This value cannot be null. |
onInterceptHoverEvent
open fun onInterceptHoverEvent(event: MotionEvent!): Boolean
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 onHoverEvent 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 onInterceptHoverEvent 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 onHoverEvent. 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 onHoverEvent and then the hovered child will receive a hover enter event.
The default implementation handles mouse hover on the scroll bars.
| Parameters | |
|---|---|
event |
MotionEvent!: The motion event that describes the hover. |
| Return | |
|---|---|
Boolean |
True if the view group would like to intercept the hover event and prevent its children from receiving it. |
onInterceptTouchEvent
open fun onInterceptTouchEvent(ev: MotionEvent!): Boolean
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:
- You will receive the down event here.
- 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.
- 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().
- 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 |
MotionEvent!: The motion event being dispatched down the hierarchy. |
| Return | |
|---|---|
Boolean |
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. |
onNestedFling
open fun onNestedFling(
target: View,
velocityX: Float,
velocityY: Float,
consumed: Boolean
): Boolean
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.
| Parameters | |
|---|---|
target |
View: View that initiated the nested scroll. This value cannot be null. |
velocityX |
Float: Horizontal velocity in pixels per second |
velocityY |
Float: Vertical velocity in pixels per second |
consumed |
Boolean: true if the child consumed the fling, false otherwise |
| Return | |
|---|---|
Boolean |
true if this parent consumed or otherwise reacted to the fling |
onNestedPreFling
open fun onNestedPreFling(
target: View,
velocityX: Float,
velocityY: Float
): Boolean
React to a nested fling before the target view consumes it.
This method siginfies 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.
| Parameters | |
|---|---|
target |
View: View that initiated the nested scroll. This value cannot be null. |
velocityX |
Float: Horizontal velocity in pixels per second |
velocityY |
Float: Vertical velocity in pixels per second |
| Return | |
|---|---|
Boolean |
true if this parent consumed the fling ahead of the target view |
onNestedPrePerformAccessibilityAction
open fun onNestedPrePerformAccessibilityAction(
target: View,
action: Int,
args: Bundle?
): Boolean
React to an accessibility action delegated by a target descendant view before the target processes it.
This method may be called by a target descendant view if the target wishes to give a view in its parent chain a chance to react to the event before normal processing occurs. Most commonly this will be a scroll event such as android.view.accessibility.AccessibilityNodeInfo#ACTION_SCROLL_FORWARD. A ViewParent that supports acting as a nested scrolling parent should override this method and act accordingly to implement scrolling via accesibility systems.
Subclasses should always call super.onNestedPrePerformAccessibilityAction
| Parameters | |
|---|---|
target |
View: The target view dispatching this action |
action |
Int: Action being performed; see android.view.accessibility.AccessibilityNodeInfo |
arguments |
Optional action arguments. This value may be null. |
args |
Bundle?: Optional action arguments |
| Return | |
|---|---|
Boolean |
false by default. Subclasses should return true if they handle the event. |
onNestedPreScroll
open fun onNestedPreScroll(
target: View,
dx: Int,
dy: Int,
consumed: IntArray
): Unit
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[]). 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.
| Parameters | |
|---|---|
target |
View: View that initiated the nested scroll. This value cannot be null. |
dx |
Int: Horizontal scroll distance in pixels |
dy |
Int: Vertical scroll distance in pixels |
consumed |
IntArray: Output. The horizontal and vertical scroll distance consumed by this parent. This value cannot be null. |
onNestedScroll
open fun onNestedScroll(
target: View,
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int
): Unit
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 onStartNestedScroll(android.view.View,android.view.View,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.
| Parameters | |
|---|---|
target |
View: The descendent view controlling the nested scroll. This value cannot be null. |
dxConsumed |
Int: Horizontal scroll distance in pixels already consumed by target |
dyConsumed |
Int: Vertical scroll distance in pixels already consumed by target |
dxUnconsumed |
Int: Horizontal scroll distance in pixels not consumed by target |
dyUnconsumed |
Int: Vertical scroll distance in pixels not consumed by target |
onNestedScrollAccepted
open fun onNestedScrollAccepted(
child: View,
target: View,
axes: Int
): Unit
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 superclass's implementation of this method if one is present.
| Parameters | |
|---|---|
child |
View: Direct child of this ViewParent containing target. This value cannot be null. |
target |
View: View that initiated the nested scroll. This value cannot be null. |
nestedScrollAxes |
Flags consisting of View.SCROLL_AXIS_HORIZONTAL, View.SCROLL_AXIS_VERTICAL or both |
onRequestSendAccessibilityEvent
open fun onRequestSendAccessibilityEvent(
child: View!,
event: AccessibilityEvent!
): Boolean
Called when a child has requested sending an AccessibilityEvent and gives an opportunity to its parent to augment the event.
If an android.view.View.AccessibilityDelegate has been specified via calling android.view.View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate) its android.view.View.AccessibilityDelegate#onRequestSendAccessibilityEvent(ViewGroup, View, AccessibilityEvent) is responsible for handling this call.
| Parameters | |
|---|---|
child |
View!: The child which requests sending the event. |
event |
AccessibilityEvent!: The event to be sent. |
| Return | |
|---|---|
Boolean |
True if the event should be sent. |
onResolvePointerIcon
open fun onResolvePointerIcon(
event: MotionEvent!,
pointerIndex: Int
): PointerIcon!
Resolve the pointer icon that should be used for specified pointer in the motion event. The default implementation will resolve the pointer icon to one set using setPointerIcon(android.view.PointerIcon) for mouse devices. Subclasses may override this to customize the icon for the given pointer. For example, to always show the PointerIcon.TYPE_HANDWRITING icon for a stylus pointer, the event can be resolved in the following way:
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
final int toolType = event.getToolType(pointerIndex);
if (!event.isFromSource(InputDevice.SOURCE_MOUSE)
&& event.isFromSource(InputDevice.SOURCE_STYLUS)
&& (toolType == MotionEvent.TOOL_TYPE_STYLUS
|| toolType == MotionEvent.TOOL_TYPE_ERASER)) {
// Show this pointer icon only if this pointer is a stylus.
return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_HANDWRITING);
}
// Use the default logic for determining the pointer icon for other non-stylus pointers,
// like for the mouse cursor.
return super.onResolvePointerIcon(event, pointerIndex);
}
| Parameters | |
|---|---|
event |
MotionEvent!: The MotionEvent that requires a pointer icon to be resolved for one of pointers. |
pointerIndex |
Int: The index of the pointer in event for which to retrieve the PointerIcon. This will be between 0 and MotionEvent.getPointerCount(). |
| Return | |
|---|---|
PointerIcon! |
the pointer icon to use for specified pointer, or null if a pointer icon is not specified and the default icon should be used. |
onStartNestedScroll
open fun onStartNestedScroll(
child: View,
target: View,
nestedScrollAxes: Int
): Boolean
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). 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 onStopNestedScroll(android.view.View).
| Parameters | |
|---|---|
child |
View: Direct child of this ViewParent containing target. This value cannot be null. |
target |
View: View that initiated the nested scroll. This value cannot be null. |
nestedScrollAxes |
Int: Flags consisting of View.SCROLL_AXIS_HORIZONTAL, View.SCROLL_AXIS_VERTICAL or both |
| Return | |
|---|---|
Boolean |
true if this ViewParent accepts the nested scroll operation |
onStopNestedScroll
open fun onStopNestedScroll(child: View): Unit
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 superclass's implementation of this method if one is present.
The default implementation of onStopNestedScroll calls stopNestedScroll() to halt any recursive nested scrolling in progress.
| Parameters | |
|---|---|
target |
View that initiated the nested scroll. This value cannot be null. |
onViewAdded
open fun onViewAdded(child: View!): Unit
Called when a new child is added to this ViewGroup. Overrides should always call super.onViewAdded.
| Parameters | |
|---|---|
child |
View!: the added child view |
onViewRemoved
open fun onViewRemoved(child: View!): Unit
Called when a child view is removed from this ViewGroup. Overrides should always call super.onViewRemoved.
| Parameters | |
|---|---|
child |
View!: the removed child view |
propagateRequestedFrameRate
open fun propagateRequestedFrameRate(
frameRate: Float,
forceOverride: Boolean
): Unit
You can set the preferred frame rate for a ViewGroup and its children using a positive number or by specifying the preferred frame rate category using constants, including REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE, REQUESTED_FRAME_RATE_CATEGORY_LOW, REQUESTED_FRAME_RATE_CATEGORY_NORMAL, REQUESTED_FRAME_RATE_CATEGORY_HIGH. Keep in mind that the preferred frame rate affects the frame rate for the next frame, so use this method carefully. It's important to note that the preference is valid as long as the ViewGroup or any of its children is invalidated. To undo the frame rate propagation, call the API with REQUESTED_FRAME_RATE_CATEGORY_DEFAULT.
| Parameters | |
|---|---|
frameRate |
Float: the preferred frame rate of the ViewGroup. |
forceOverride |
Boolean: indicate whether it should override the frame rate of all the children with the given frame rate. |
recomputeViewAttributes
open fun recomputeViewAttributes(child: View!): Unit
Tell view hierarchy that the global view attributes need to be re-evaluated.
| Parameters | |
|---|---|
child |
View!: View whose attributes have changed. |
removeAllViews
open fun removeAllViews(): Unit
Call this method to remove all child views from the ViewGroup.
Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
removeAllViewsInLayout
open fun removeAllViewsInLayout(): Unit
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 draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
removeView
open fun removeView(view: View!): Unit
Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
removeViewAt
open fun removeViewAt(index: Int): Unit
Removes the view at the specified position in the group.
Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
| Parameters | |
|---|---|
index |
Int: the position in the group of the view to remove |
removeViewInLayout
open fun removeViewInLayout(view: View!): Unit
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 draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
| Parameters | |
|---|---|
view |
View!: the view to remove from the group |
removeViews
open fun removeViews(
start: Int,
count: Int
): Unit
Removes the specified range of views from the group.
Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
| Parameters | |
|---|---|
start |
Int: the first position in the group of the range of views to remove |
count |
Int: the number of views to remove |
removeViewsInLayout
open fun removeViewsInLayout(
start: Int,
count: Int
): Unit
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 draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.
| Parameters | |
|---|---|
start |
Int: the index of the first view to remove from the group |
count |
Int: the number of views to remove from the group |
requestChildFocus
open fun requestChildFocus(
child: View!,
focused: View!
): Unit
Called when a child of this parent wants focus
| Parameters | |
|---|---|
child |
View!: 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 |
View!: The view that is a descendant of child that actually has focus |
requestChildRectangleOnScreen
open fun requestChildRectangleOnScreen(
child: View,
rectangle: Rect!,
immediate: Boolean
): Boolean
Called when a child of this group wants a particular rectangle to be positioned onto the screen. ViewGroups overriding this can trust that:
childwill be a direct child of this grouprectanglewill 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
| Parameters | |
|---|---|
child |
View: The direct child making the request. This value cannot be null. |
rectangle |
Rect!: The rectangle in the child's coordinates the child wishes to be on the screen. |
immediate |
Boolean: True to forbid animated or delayed scrolling, false otherwise |
| Return | |
|---|---|
Boolean |
Whether the group scrolled to handle the operation |
requestDisallowInterceptTouchEvent
open fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean): Unit
Called when a child does not want this parent and its ancestors to intercept touch events with ViewGroup.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 |
Boolean: True if the child does not want the parent to intercept touch events. |
requestFocus
open fun requestFocus(
direction: Int,
previouslyFocusedRect: Rect!
): Boolean
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 (isFocusable returns false), or if it is focusable and it is not focusable in touch mode (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 android.view.ViewGroup#getDescendantFocusability() equal to ViewGroup.FOCUS_BLOCK_DESCENDANTS. See also 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,android.graphics.Rect) to find focus within the children of this group when appropriate.
| Parameters | |
|---|---|
direction |
Int: One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
previouslyFocusedRect |
Rect!: 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. |
| Return | |
|---|---|
Boolean |
Whether this view or one of its descendants actually took focus. |
requestSendAccessibilityEvent
open fun requestSendAccessibilityEvent(
child: View,
event: AccessibilityEvent!
): Boolean
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 |
View: The child which requests sending the event. This value cannot be null. |
event |
AccessibilityEvent!: The event to be sent. |
| Return | |
|---|---|
Boolean |
True if the event was sent. |
requestTransparentRegion
open fun requestTransparentRegion(child: View!): Unit
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 |
View!: the view requesting the transparent region computation |
restoreDefaultFocus
open fun restoreDefaultFocus(): Boolean
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 requestFocus(int).
| Return | |
|---|---|
Boolean |
Whether this view or one of its descendants actually took focus |
scheduleLayoutAnimation
open fun scheduleLayoutAnimation(): Unit
Schedules the layout animation to be played after the next layout pass of this view group. This can be used to restart the layout animation when the content of the view group changes or when the activity is paused and resumed.
setAddStatesFromChildren
open fun setAddStatesFromChildren(addsStates: Boolean): Unit
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.
setAlwaysDrawnWithCacheEnabled
open funsetAlwaysDrawnWithCacheEnabled(always: Boolean): Unit
Deprecated: As of android.os.Build.VERSION_CODES#M, this property is ignored. Child views may no longer have their caching behavior disabled by parents.
Indicates whether this ViewGroup will always try to draw its children using their drawing cache. This property can be set to true when the cache rendering is slightly different from the children's normal rendering. Renderings can be different, for instance, when the cache's quality is set to low. When this property is disabled, the ViewGroup will use the drawing cache of its children only when asked to. It's usually the task of subclasses to tell ViewGroup when to start using the drawing cache and when to stop using it.
| Parameters | |
|---|---|
always |
Boolean: true to always draw with the drawing cache, false otherwise |
setAnimationCacheEnabled
open funsetAnimationCacheEnabled(enabled: Boolean): Unit
Deprecated: As of android.os.Build.VERSION_CODES#M, this property is ignored. Caching behavior of children may be controlled through View.setLayerType(int, Paint).
Enables or disables the children's drawing cache during a layout animation. By default, the drawing cache is enabled but this will prevent nested layout animations from working. To nest animations, you must disable the cache.
| Parameters | |
|---|---|
enabled |
Boolean: true to enable the animation cache, false otherwise |
setClipChildren
open fun setClipChildren(clipChildren: Boolean): Unit
By default, children are clipped to their bounds before drawing. This allows view groups to override this behavior for animations, etc.
| Parameters | |
|---|---|
clipChildren |
Boolean: true to clip children to their bounds, false otherwise |
setClipToPadding
open fun setClipToPadding(clipToPadding: Boolean): Unit
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 |
Boolean: true to clip children to the padding of the group, and resize (but not clip) any EdgeEffect to the padded region. False otherwise. |
setDescendantFocusability
open fun setDescendantFocusability(focusability: Int): Unit
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 requestFocus(int,android.graphics.Rect).
| Parameters | |
|---|---|
focusability |
Int: one of FOCUS_BEFORE_DESCENDANTS, FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS. |
setLayoutAnimation
open fun setLayoutAnimation(controller: LayoutAnimationController!): Unit
Sets the layout animation controller used to animate the group's children after the first layout.
| Parameters | |
|---|---|
controller |
LayoutAnimationController!: the animation controller |
setLayoutAnimationListener
open fun setLayoutAnimationListener(animationListener: Animation.AnimationListener!): Unit
Specifies the animation listener to which layout animation events must be sent. Only android.view.animation.Animation.AnimationListener#onAnimationStart(Animation) and android.view.animation.Animation.AnimationListener#onAnimationEnd(Animation) are invoked.
| Parameters | |
|---|---|
animationListener |
Animation.AnimationListener!: the layout animation listener |
setLayoutMode
open fun setLayoutMode(layoutMode: Int): Unit
Sets the basis of alignment during the layout of this ViewGroup. Valid values are either LAYOUT_MODE_CLIP_BOUNDS or LAYOUT_MODE_OPTICAL_BOUNDS.
| Parameters | |
|---|---|
layoutMode |
Int: the layout mode to use during layout operations |
See Also
setLayoutTransition
open fun setLayoutTransition(transition: LayoutTransition!): Unit
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 |
LayoutTransition!: The LayoutTransition object that will animated changes in layout. A value of null means no transition will run on layout changes. |
setMotionEventSplittingEnabled
open fun setMotionEventSplittingEnabled(split: Boolean): Unit
Enable or disable the splitting of MotionEvents to multiple children during touch event dispatch. This behavior is enabled by default for applications that target an SDK version of Build.VERSION_CODES.HONEYCOMB or newer.
When this option is enabled MotionEvents may be split and dispatched to different child views depending on where each pointer initially went down. This allows for user interactions such as scrolling two panes of content independently, chording of buttons, and performing independent gestures on different pieces of content.
| Parameters | |
|---|---|
split |
Boolean: true to allow MotionEvents to be split and dispatched to multiple child views. false to only allow one child view to be the target of any MotionEvent received by this ViewGroup. |
setOnHierarchyChangeListener
open fun setOnHierarchyChangeListener(listener: ViewGroup.OnHierarchyChangeListener!): Unit
Register a callback to be invoked when a child is added to or removed from this view.
| Parameters | |
|---|---|
listener |
ViewGroup.OnHierarchyChangeListener!: the callback to invoke on hierarchy change |
setPersistentDrawingCache
open funsetPersistentDrawingCache(drawingCacheToKeep: Int): Unit
Deprecated: The view drawing cache was largely made obsolete with the introduction of hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache layers are largely unnecessary and can easily result in a net loss in performance due to the cost of creating and updating the layer. In the rare cases where caching layers are useful, such as for alpha animations, setLayerType(int,android.graphics.Paint) handles this with hardware rendering. For software-rendered snapshots of a small part of the View hierarchy or individual Views it is recommended to create a Canvas from either a Bitmap or android.graphics.Picture and call draw(android.graphics.Canvas) on the View. However these software-rendered usages are discouraged and have compatibility issues with hardware-only rendering features such as Config.HARDWARE bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback reports or unit testing the PixelCopy API is recommended.
Indicates what types of drawing caches should be kept in memory after they have been created.
| Parameters | |
|---|---|
drawingCacheToKeep |
Int: one or a combination of PERSISTENT_NO_CACHE, PERSISTENT_ANIMATION_CACHE, PERSISTENT_SCROLLING_CACHE and PERSISTENT_ALL_CACHES |
setRequestedFrameRate
open fun setRequestedFrameRate(frameRate: Float): Unit
You can set the preferred frame rate for a ViewGroup using a positive number or by specifying the preferred frame rate category using constants, including REQUESTED_FRAME_RATE_CATEGORY_NO_PREFERENCE, REQUESTED_FRAME_RATE_CATEGORY_LOW, REQUESTED_FRAME_RATE_CATEGORY_NORMAL, REQUESTED_FRAME_RATE_CATEGORY_HIGH. Keep in mind that the preferred frame rate affects the frame rate for the next frame, so use this method carefully. It's important to note that the preference is valid as long as the ViewGroup is invalidated. Please also be aware that the requested frame rate will not propagate to child views.
| Parameters | |
|---|---|
frameRate |
Float: the preferred frame rate of the ViewGroup. |
setTouchscreenBlocksFocus
open fun setTouchscreenBlocksFocus(touchscreenBlocksFocus: Boolean): Unit
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 |
Boolean: true to enable blocking focus in the presence of a touchscreen |
setTransitionGroup
open fun setTransitionGroup(isTransitionGroup: Boolean): Unit
Changes whether or not this ViewGroup should be treated as a single entity during Activity Transitions.
| Parameters | |
|---|---|
isTransitionGroup |
Boolean: 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. |
setWindowInsetsAnimationCallback
open fun setWindowInsetsAnimationCallback(callback: WindowInsetsAnimation.Callback?): Unit
Sets a WindowInsetsAnimation.Callback to be notified about animations of windows that cause insets.
The callback's dispatch mode will affect whether animation callbacks are dispatched to the children of this view.
| Parameters | |
|---|---|
callback |
WindowInsetsAnimation.Callback?: This value may be null. |
shouldDelayChildPressedState
open fun shouldDelayChildPressedState(): Boolean
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.
showContextMenuForChild
open fun showContextMenuForChild(originalView: View!): Boolean
Shows the 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, ViewManager.addView(View, android.view.ViewGroup.LayoutParams)) then it should override this and show the context menu.
| Parameters | |
|---|---|
originalView |
View!: the source view where the context menu was first invoked |
| Return | |
|---|---|
Boolean |
true if the context menu was shown, false otherwise |
showContextMenuForChild
open fun showContextMenuForChild(
originalView: View!,
x: Float,
y: Float
): Boolean
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, android.view.ViewGroup.LayoutParams)) then it should override this and show the context menu.
If a subclass overrides this method it should also override showContextMenuForChild(android.view.View).
| Parameters | |
|---|---|
originalView |
View!: the source view where the context menu was first invoked |
x |
Float: the X coordinate in pixels relative to the original view to which the menu should be anchored, or Float.NaN to disable anchoring |
y |
Float: the Y coordinate in pixels relative to the original view to which the menu should be anchored, or Float.NaN to disable anchoring |
| Return | |
|---|---|
Boolean |
true if the context menu was shown, false otherwise |
startActionModeForChild
open fun startActionModeForChild(
originalView: View!,
callback: ActionMode.Callback!
): ActionMode!
Start an action mode for the specified view with the default type ActionMode.TYPE_PRIMARY.
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, android.view.ViewGroup.LayoutParams)) then it should override this and start the action mode.
| Parameters | |
|---|---|
originalView |
View!: The source view where the action mode was first invoked |
callback |
ActionMode.Callback!: The callback that will handle lifecycle events for the action mode |
| Return | |
|---|---|
ActionMode! |
The new action mode if it was started, null otherwise |
startActionModeForChild
open fun startActionModeForChild(
originalView: View!,
callback: ActionMode.Callback!,
type: Int
): ActionMode!
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, android.view.ViewGroup.LayoutParams)) then it should override this and start the action mode.
| Parameters | |
|---|---|
originalView |
View!: The source view where the action mode was first invoked |
callback |
ActionMode.Callback!: The callback that will handle lifecycle events for the action mode |
type |
Int: One of ActionMode.TYPE_PRIMARY or ActionMode.TYPE_FLOATING. |
| Return | |
|---|---|
ActionMode! |
The new action mode if it was started, null otherwise |
startLayoutAnimation
open fun startLayoutAnimation(): Unit
Runs the layout animation. Calling this method triggers a relayout of this view group.
startViewTransition
open fun startViewTransition(view: View!): Unit
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 android.app.Fragment and android.animation.LayoutTransition to animate the removal of views. A call to this method should always be accompanied by a later call to endViewTransition(android.view.View), such as after an animation on the View has finished, so that the View finally gets removed.
| Parameters | |
|---|---|
view |
View!: The View object to be kept visible even if it gets removed from its parent. |
suppressLayout
open fun suppressLayout(suppress: Boolean): Unit
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.
updateViewLayout
open fun updateViewLayout(
view: View!,
params: ViewGroup.LayoutParams!
): Unit
Protected methods
addViewInLayout
protected open fun addViewInLayout(
child: View!,
index: Int,
params: ViewGroup.LayoutParams!
): Boolean
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 |
View!: the view to add to the group |
index |
Int: the index at which the child must be added or -1 to add last |
params |
ViewGroup.LayoutParams!: the layout parameters to associate with the child |
| Return | |
|---|---|
Boolean |
true if the child was added, false otherwise |
addViewInLayout
protected open fun addViewInLayout(
child: View!,
index: Int,
params: ViewGroup.LayoutParams!,
preventRequestLayout: Boolean
): Boolean
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 |
View!: the view to add to the group |
index |
Int: the index at which the child must be added or -1 to add last |
params |
ViewGroup.LayoutParams!: the layout parameters to associate with the child |
preventRequestLayout |
Boolean: if true, calling this method will not trigger a layout request on child |
| Return | |
|---|---|
Boolean |
true if the child was added, false otherwise |
attachLayoutAnimationParameters
protected open fun attachLayoutAnimationParameters(
child: View!,
params: ViewGroup.LayoutParams!,
index: Int,
count: Int
): Unit
Subclasses should override this method to set layout animation parameters on the supplied child.
| Parameters | |
|---|---|
child |
View!: the child to associate with animation parameters |
params |
ViewGroup.LayoutParams!: the child's layout parameters which hold the animation parameters |
index |
Int: the index of the child in the view group |
count |
Int: the number of children in the view group |
attachViewToParent
protected open fun attachViewToParent(
child: View!,
index: Int,
params: ViewGroup.LayoutParams!
): Unit
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 #requestLayout() or invalidate() calls. For example, callers can post a Runnable which performs a #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 |
View!: the child to attach |
index |
Int: the index at which the child should be attached |
params |
ViewGroup.LayoutParams!: the layout parameters of the child |
canAnimate
protected open fun canAnimate(): Boolean
Indicates whether the view group has the ability to animate its children after the first layout.
| Return | |
|---|---|
Boolean |
true if the children can be animated, false otherwise |
checkLayoutParams
protected open fun checkLayoutParams(p: ViewGroup.LayoutParams!): Boolean
cleanupLayoutState
protected open fun cleanupLayoutState(child: View!): Unit
Prevents the specified child to be laid out during the next layout pass.
| Parameters | |
|---|---|
child |
View!: the child on which to perform the cleanup |
detachAllViewsFromParent
protected open fun detachAllViewsFromParent(): Unit
Detaches all views from the parent. Detaching a view should be followed either by a call to attachViewToParent(android.view.View,int,android.view.ViewGroup.LayoutParams) or a call to removeDetachedView(android.view.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).
detachViewFromParent
protected open fun detachViewFromParent(child: View!): Unit
Detaches a view from its parent. Detaching a view should be followed either by a call to attachViewToParent(android.view.View,int,android.view.ViewGroup.LayoutParams) or a call to removeDetachedView(android.view.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 |
View!: the child to detach |
detachViewFromParent
protected open fun detachViewFromParent(index: Int): Unit
Detaches a view from its parent. Detaching a view should be followed either by a call to attachViewToParent(android.view.View,int,android.view.ViewGroup.LayoutParams) or a call to removeDetachedView(android.view.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 |
Int: the index of the child to detach |
detachViewsFromParent
protected open fun detachViewsFromParent(
start: Int,
count: Int
): Unit
Detaches a range of views from their parents. Detaching a view should be followed either by a call to attachViewToParent(android.view.View,int,android.view.ViewGroup.LayoutParams) or a call to removeDetachedView(android.view.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 |
Int: the first index of the childrend range to detach |
count |
Int: the number of children to detach |
dispatchDraw
protected open fun dispatchDraw(canvas: Canvas): Unit
Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).
| Parameters | |
|---|---|
canvas |
Canvas: This value cannot be null. |
dispatchFreezeSelfOnly
protected open fun dispatchFreezeSelfOnly(container: SparseArray<Parcelable!>!): Unit
Perform dispatching of a saveHierarchyState(android.util.SparseArray) freeze()} to only this view, not to its children. For use when overriding dispatchSaveInstanceState(android.util.SparseArray) dispatchFreeze()} to allow subclasses to freeze their own state but not the state of their children.
| Parameters | |
|---|---|
container |
SparseArray<Parcelable!>!: the container |
dispatchGenericFocusedEvent
protected open fun dispatchGenericFocusedEvent(event: MotionEvent!): Boolean
Dispatch a generic motion event to the currently focused view.
Do not call this method directly. Call dispatchGenericMotionEvent(android.view.MotionEvent) instead.
| Parameters | |
|---|---|
event |
MotionEvent!: The motion event to be dispatched. |
| Return | |
|---|---|
Boolean |
True if the event was handled by the view, false otherwise. |
dispatchGenericPointerEvent
protected open fun dispatchGenericPointerEvent(event: MotionEvent!): Boolean
Dispatch a generic motion event to the view under the first pointer.
Do not call this method directly. Call dispatchGenericMotionEvent(android.view.MotionEvent) instead.
| Parameters | |
|---|---|
event |
MotionEvent!: The motion event to be dispatched. |
| Return | |
|---|---|
Boolean |
True if the event was handled by the view, false otherwise. |
dispatchHoverEvent
protected open fun dispatchHoverEvent(event: MotionEvent!): Boolean
Dispatch a hover event.
Do not call this method directly. Call dispatchGenericMotionEvent(android.view.MotionEvent) instead.
| Parameters | |
|---|---|
event |
MotionEvent!: The motion event to be dispatched. |
| Return | |
|---|---|
Boolean |
True if the event was handled by the view, false otherwise. |
dispatchRestoreInstanceState
protected open fun dispatchRestoreInstanceState(container: SparseArray<Parcelable!>!): Unit
Called by restoreHierarchyState(android.util.SparseArray) to retrieve the state for this view and its children. May be overridden to modify how restoring happens to a view's children; for example, some views may want to not store state for their children.
| Parameters | |
|---|---|
container |
SparseArray<Parcelable!>!: The SparseArray which holds previously saved state. |
dispatchSaveInstanceState
protected open fun dispatchSaveInstanceState(container: SparseArray<Parcelable!>!): Unit
Called by saveHierarchyState(android.util.SparseArray) to store the state for this view and its children. May be overridden to modify how freezing happens to a view's children; for example, some views may want to not store state for their children.
| Parameters | |
|---|---|
container |
SparseArray<Parcelable!>!: The SparseArray in which to save the view's state. |
dispatchSetPressed
protected open fun dispatchSetPressed(pressed: Boolean): Unit
Dispatch setPressed to all of this View's children.
| Parameters | |
|---|---|
pressed |
Boolean: The new pressed state |
dispatchThawSelfOnly
protected open fun dispatchThawSelfOnly(container: SparseArray<Parcelable!>!): Unit
Perform dispatching of a restoreHierarchyState(android.util.SparseArray) to only this view, not to its children. For use when overriding dispatchRestoreInstanceState(android.util.SparseArray) to allow subclasses to thaw their own state but not the state of their children.
| Parameters | |
|---|---|
container |
SparseArray<Parcelable!>!: the container |
dispatchVisibilityChanged
protected open fun dispatchVisibilityChanged(
changedView: View,
visibility: Int
): Unit
Dispatch a view visibility change down the view hierarchy. ViewGroups should override to route to their children.
| Parameters | |
|---|---|
changedView |
View: The view whose visibility changed. Could be 'this' or an ancestor view. This value cannot be null. |
visibility |
Int: The new visibility of changedView: VISIBLE, INVISIBLE or GONE. Value is one of the following: |
drawChild
protected open fun drawChild(
canvas: Canvas,
child: View!,
drawingTime: Long
): Boolean
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 |
Canvas: The canvas on which to draw the child. This value cannot be null. |
child |
View!: Who to draw |
drawingTime |
Long: The time at which draw is occurring |
| Return | |
|---|---|
Boolean |
True if an invalidate() was issued |
drawableStateChanged
protected open fun drawableStateChanged(): Unit
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.
If you override this method you must call through to the superclass implementation.
generateDefaultLayoutParams
protected open fun generateDefaultLayoutParams(): ViewGroup.LayoutParams!
Returns a set of default layout parameters. These parameters are requested when the View passed to addView(android.view.View) has no layout parameters already set. If null is returned, an exception is thrown from addView.
| Return | |
|---|---|
ViewGroup.LayoutParams! |
a set of default layout parameters or null |
generateLayoutParams
protected open fun generateLayoutParams(p: ViewGroup.LayoutParams!): ViewGroup.LayoutParams!
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(android.view.ViewGroup.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 |
ViewGroup.LayoutParams!: The layout parameters to convert into a suitable set of layout parameters for this ViewGroup. |
| Return | |
|---|---|
ViewGroup.LayoutParams! |
an instance of android.view.ViewGroup.LayoutParams or one of its descendants |
getChildDrawingOrder
protected open fun getChildDrawingOrder(
childCount: Int,
drawingPosition: Int
): Int
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 |
Int: the drawing order position. |
| Return | |
|---|---|
Int |
the container position of a child for this drawing order position. |
getChildStaticTransformation
protected open fun getChildStaticTransformation(
child: View!,
t: Transformation!
): Boolean
Sets t to be the static transformation of the child, if set, returning a boolean to indicate whether a static transform was set. The default implementation simply returns false; subclasses may override this method for different behavior. setStaticTransformationsEnabled(boolean) must be set to true for this method to be called.
| Parameters | |
|---|---|
child |
View!: The child view whose static transform is being requested |
t |
Transformation!: The Transformation which will hold the result |
| Return | |
|---|---|
Boolean |
true if the transformation was set, false otherwise |
isChildrenDrawingOrderEnabled
protected open fun isChildrenDrawingOrderEnabled(): Boolean
Indicates whether the ViewGroup is drawing its children in the order defined by getChildDrawingOrder(int,int).
| Return | |
|---|---|
Boolean |
true if children drawing order is defined by getChildDrawingOrder(int,int), false otherwise |
isChildrenDrawnWithCacheEnabled
protected open funisChildrenDrawnWithCacheEnabled(): Boolean
Deprecated: As of android.os.Build.VERSION_CODES#M, this property is ignored. Child views may no longer be forced to cache their rendering state by their parents. Use View.setLayerType(int, Paint) on individual Views instead.
Indicates whether the ViewGroup is currently drawing its children using their drawing cache.
| Return | |
|---|---|
Boolean |
true if children should be drawn with their cache, false otherwise |
measureChild
protected open fun measureChild(
child: View!,
parentWidthMeasureSpec: Int,
parentHeightMeasureSpec: Int
): Unit
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 |
View!: The child to measure |
parentWidthMeasureSpec |
Int: The width requirements for this view |
parentHeightMeasureSpec |
Int: The height requirements for this view |
measureChildWithMargins
protected open fun measureChildWithMargins(
child: View!,
parentWidthMeasureSpec: Int,
widthUsed: Int,
parentHeightMeasureSpec: Int,
heightUsed: Int
): Unit
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 |
View!: The child to measure |
parentWidthMeasureSpec |
Int: The width requirements for this view |
widthUsed |
Int: Extra space that has been used up by the parent horizontally (possibly by other children of the parent) |
parentHeightMeasureSpec |
Int: The height requirements for this view |
heightUsed |
Int: Extra space that has been used up by the parent vertically (possibly by other children of the parent) |
measureChildren
protected open fun measureChildren(
widthMeasureSpec: Int,
heightMeasureSpec: Int
): Unit
Ask all of 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 |
Int: The width requirements for this view |
heightMeasureSpec |
Int: The height requirements for this view |
onAttachedToWindow
protected open fun onAttachedToWindow(): Unit
This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int,int).
If you override this method you must call through to the superclass implementation.
onCreateDrawableState
protected open fun onCreateDrawableState(extraSpace: Int): IntArray!
Generate the new android.graphics.drawable.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 getDrawableState.
| Parameters | |
|---|---|
extraSpace |
Int: 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. |
| Return | |
|---|---|
IntArray! |
Returns an array holding the current Drawable state of the view. |
onDetachedFromWindow
protected open fun onDetachedFromWindow(): Unit
This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
If you override this method you must call through to the superclass implementation.
onLayout
protected abstract fun onLayout(
changed: Boolean,
l: Int,
t: Int,
r: Int,
b: Int
): Unit
Called from layout 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.
| Parameters | |
|---|---|
changed |
Boolean: 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 |
onRequestFocusInDescendants
protected open fun onRequestFocusInDescendants(
direction: Int,
previouslyFocusedRect: Rect!
): Boolean
Look for a descendant to call android.view.View#requestFocus on. Called by ViewGroup.requestFocus(int, android.graphics.Rect) when it wants to request focus within its children. Override this to customize how your ViewGroup requests focus within its children.
| Parameters | |
|---|---|
direction |
Int: One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
previouslyFocusedRect |
Rect!: 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. |
| Return | |
|---|---|
Boolean |
Whether focus was taken. |
removeDetachedView
protected open fun removeDetachedView(
child: View!,
animate: Boolean
): Unit
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 #requestLayout() or invalidate() calls. For example, callers can post a Runnable which performs a #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 |
View!: the child to be definitely removed from the view hierarchy |
animate |
Boolean: if true and the view has an animation, the view is placed in the disappearing views list, otherwise, it is detached from the window |
setChildrenDrawingCacheEnabled
protected open funsetChildrenDrawingCacheEnabled(enabled: Boolean): Unit
Deprecated: The view drawing cache was largely made obsolete with the introduction of hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache layers are largely unnecessary and can easily result in a net loss in performance due to the cost of creating and updating the layer. In the rare cases where caching layers are useful, such as for alpha animations, setLayerType(int,android.graphics.Paint) handles this with hardware rendering. For software-rendered snapshots of a small part of the View hierarchy or individual Views it is recommended to create a Canvas from either a Bitmap or android.graphics.Picture and call draw(android.graphics.Canvas) on the View. However these software-rendered usages are discouraged and have compatibility issues with hardware-only rendering features such as Config.HARDWARE bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback reports or unit testing the PixelCopy API is recommended.
Enables or disables the drawing cache for each child of this view group.
| Parameters | |
|---|---|
enabled |
Boolean: true to enable the cache, false to dispose of it |
setChildrenDrawingOrderEnabled
protected open fun setChildrenDrawingOrderEnabled(enabled: Boolean): Unit
Tells the ViewGroup whether to draw its children in the order defined by the method getChildDrawingOrder(int,int).
Note that Z reordering, done by dispatchDraw(android.graphics.Canvas), will override custom child ordering done via this method.
| Parameters | |
|---|---|
enabled |
Boolean: true if the order of the children when drawing is determined by getChildDrawingOrder(int,int), false otherwise |
setChildrenDrawnWithCacheEnabled
protected open funsetChildrenDrawnWithCacheEnabled(enabled: Boolean): Unit
Deprecated: As of android.os.Build.VERSION_CODES#M, this property is ignored. Child views may no longer be forced to cache their rendering state by their parents. Use View.setLayerType(int, Paint) on individual Views instead.
Tells the ViewGroup to draw its children using their drawing cache. This property is ignored when isAlwaysDrawnWithCacheEnabled() is true. A child's drawing cache will be used only if it has been enabled. Subclasses should call this method to start and stop using the drawing cache when they perform performance sensitive operations, like scrolling or animating.
| Parameters | |
|---|---|
enabled |
Boolean: true if children should be drawn with their cache, false otherwise |
setStaticTransformationsEnabled
protected open fun setStaticTransformationsEnabled(enabled: Boolean): Unit
When this property is set to true, this ViewGroup supports static transformations on children; this causes getChildStaticTransformation(android.view.View,android.view.animation.Transformation) to be invoked when a child is drawn. Any subclass overriding getChildStaticTransformation(android.view.View,android.view.animation.Transformation) should set this property to true.
| Parameters | |
|---|---|
enabled |
Boolean: True to enable static transformations on children, false otherwise. |