# ViewGroupCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/view/ViewGroupCompat.java+class:androidx.core.view.ViewGroupCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***


```
public final class ViewGroupCompat
```

<br />

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/view/ViewGroup.html`.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#LAYOUT_MODE_CLIP_BOUNDS() = 0` This constant is a `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#setLayoutMode(android.view.ViewGroup,int)`. |
| `static final int` | `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#LAYOUT_MODE_OPTICAL_BOUNDS() = 1` This constant is a `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#setLayoutMode(android.view.ViewGroup,int)`. |

| ### Public methods |
|---|---|
| `static int` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "group.getLayoutMode()") [getLayoutMode](https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#getLayoutMode(android.view.ViewGroup))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.html group)` **This method is deprecated.** Call `https://developer.android.com/reference/android/view/ViewGroup.html#getLayoutMode()` directly. <br /> |
| `static int` | `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#getNestedScrollAxes(android.view.ViewGroup)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.html group)` Return the current axes of nested scrolling for this ViewGroup. |
| `static void` | `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#installCompatInsetsDispatch(android.view.View)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html root)` Installs a custom `https://developer.android.com/reference/android/view/View.OnApplyWindowInsetsListener.html` which dispatches WindowInsets to the given root and its descendants in a way compatible with Android R+ that consuming or modifying insets will only affect the descendants. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#isTransitionGroup(android.view.ViewGroup)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.html group)` Returns true if this ViewGroup should be considered as a single entity for removal when executing an Activity transition. |
| `static boolean` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "group.onRequestSendAccessibilityEvent(child, event)") [onRequestSendAccessibilityEvent](https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#onRequestSendAccessibilityEvent(android.view.ViewGroup,android.view.View,android.view.accessibility.AccessibilityEvent))( https://developer.android.com/reference/android/view/ViewGroup.html group, https://developer.android.com/reference/android/view/View.html child, https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event )` **This method is deprecated.** Use `https://developer.android.com/reference/android/view/ViewGroup.html#onRequestSendAccessibilityEvent(android.view.View, android.view.accessibility.AccessibilityEvent)` directly. <br /> |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "group.setLayoutMode(mode)") [setLayoutMode](https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#setLayoutMode(android.view.ViewGroup,int))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.html group, int mode)` **This method is deprecated.** Call setLayoutMode directly. <br /> |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "group.setMotionEventSplittingEnabled(split)") [setMotionEventSplittingEnabled](https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#setMotionEventSplittingEnabled(android.view.ViewGroup,boolean))(https://developer.android.com/reference/android/view/ViewGroup.html group, boolean split)` **This method is deprecated.** Use `https://developer.android.com/reference/android/view/ViewGroup.html#setMotionEventSplittingEnabled(boolean)` directly. <br /> |
| `static void` | `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#setTransitionGroup(android.view.ViewGroup,boolean)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.html group, boolean isTransitionGroup)` Changes whether or not this ViewGroup should be treated as a single entity during Activity Transitions. |

## Constants

### LAYOUT_MODE_CLIP_BOUNDS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static final int LAYOUT_MODE_CLIP_BOUNDS = 0
```

This constant is a `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#setLayoutMode(android.view.ViewGroup,int)`. Clip bounds are the raw values of `https://developer.android.com/reference/android/view/View.html#getLeft()`, `https://developer.android.com/reference/android/view/View.html#getTop()`, `https://developer.android.com/reference/android/view/View.html#getRight()` and `https://developer.android.com/reference/android/view/View.html#getBottom()`.

### LAYOUT_MODE_OPTICAL_BOUNDS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static final int LAYOUT_MODE_OPTICAL_BOUNDS = 1
```

This constant is a `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#setLayoutMode(android.view.ViewGroup,int)`. 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.

## Public methods

### getLayoutMode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.15.0](https://developer.android.com/jetpack/androidx/releases/core#1.15.0)

```
@ReplaceWith(expression = "group.getLayoutMode()")
public static int [getLayoutMode](https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#getLayoutMode(android.view.ViewGroup))(@NonNull ViewGroup group)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Call `https://developer.android.com/reference/android/view/ViewGroup.html#getLayoutMode()` directly.

Returns the basis of alignment during layout operations on this ViewGroup: either `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#LAYOUT_MODE_CLIP_BOUNDS()` or `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#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 `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#LAYOUT_MODE_CLIP_BOUNDS()`.

| Returns |
|---|---|
| `int` | the layout mode to use during layout operations |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#setLayoutMode(android.view.ViewGroup,int)` |   |

### getNestedScrollAxes

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static int getNestedScrollAxes(@NonNull ViewGroup group)
```

Return the current axes of nested scrolling for this ViewGroup.

A ViewGroup returning something other than `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_NONE()` is currently acting as a nested scrolling parent for one or more descendant views in the hierarchy.

| Returns |
|---|---|
| `int` | Flags indicating the current axes of nested scrolling |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_HORIZONTAL()` |   |
| `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_VERTICAL()` |   |
| `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_NONE()` |   |

### installCompatInsetsDispatch

Added in [1.16.0](https://developer.android.com/jetpack/androidx/releases/core#1.16.0)

```
public static void installCompatInsetsDispatch(@NonNull View root)
```

Installs a custom `https://developer.android.com/reference/android/view/View.OnApplyWindowInsetsListener.html` which dispatches WindowInsets to the given root and its descendants in a way compatible with Android R+ that consuming or modifying insets will only affect the descendants.

Note: When using this method, ensure that ViewCompat.setOnApplyWindowInsetsListener() is used instead of the platform call.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html root` | The root view that the custom listener is installed on. Note: the listener will consume the insets, so make sure the given root is the root view of the window, or its siblings might not be able to get insets dispatched. |

### isTransitionGroup

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static boolean isTransitionGroup(@NonNull ViewGroup group)
```

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.

### onRequestSendAccessibilityEvent

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
@ReplaceWith(expression = "group.onRequestSendAccessibilityEvent(child, event)")
public static boolean [onRequestSendAccessibilityEvent](https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#onRequestSendAccessibilityEvent(android.view.ViewGroup,android.view.View,android.view.accessibility.AccessibilityEvent))(
    ViewGroup group,
    View child,
    AccessibilityEvent event
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.html#onRequestSendAccessibilityEvent(android.view.View, android.view.accessibility.AccessibilityEvent)` directly.

Called when a child has requested sending an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` and gives an opportunity to its parent to augment the event.

If an `https://developer.android.com/reference/androidx/core/view/AccessibilityDelegateCompat` has been specified via calling `https://developer.android.com/reference/androidx/core/view/ViewCompat#setAccessibilityDelegate(android.view.View,androidx.core.view.AccessibilityDelegateCompat)` its `https://developer.android.com/reference/androidx/core/view/AccessibilityDelegateCompat#onRequestSendAccessibilityEvent(android.view.ViewGroup,android.view.View,android.view.accessibility.AccessibilityEvent)` is responsible for handling this call.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/ViewGroup.html group` | The group whose method to invoke. |
| `https://developer.android.com/reference/android/view/View.html child` | The child which requests sending the event. |
| `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html event` | The event to be sent. |

| Returns |
|---|---|
| `boolean` | True if the event should be sent. |

### setLayoutMode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.15.0](https://developer.android.com/jetpack/androidx/releases/core#1.15.0)

```
@ReplaceWith(expression = "group.setLayoutMode(mode)")
public static void [setLayoutMode](https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#setLayoutMode(android.view.ViewGroup,int))(@NonNull ViewGroup group, int mode)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Call setLayoutMode directly.

Sets the basis of alignment during the layout of this ViewGroup. Valid values are either `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#LAYOUT_MODE_CLIP_BOUNDS()` or `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#LAYOUT_MODE_OPTICAL_BOUNDS()`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.html group` | ViewGroup for which to set the mode. |
| `int mode` | the layout mode to use during layout operations |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#getLayoutMode(android.view.ViewGroup)` |   |

### setMotionEventSplittingEnabled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
@ReplaceWith(expression = "group.setMotionEventSplittingEnabled(split)")
public static void [setMotionEventSplittingEnabled](https://developer.android.com/reference/androidx/core/view/ViewGroupCompat#setMotionEventSplittingEnabled(android.view.ViewGroup,boolean))(ViewGroup group, boolean split)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.html#setMotionEventSplittingEnabled(boolean)` directly.

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 11 (Honeycomb) or newer. On earlier platform versions this feature was not supported and this method is a no-op.

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 |
|---|---|
| `https://developer.android.com/reference/android/view/ViewGroup.html group` | ViewGroup to modify |
| `boolean split` | `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. |

### setTransitionGroup

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static void setTransitionGroup(@NonNull ViewGroup group, boolean isTransitionGroup)
```

Changes whether or not this ViewGroup should be treated as a single entity during Activity Transitions.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.html group` | ViewGroup for which to set the mode. |
| `boolean isTransitionGroup` | Whether or not the ViewGroup should be treated as a unit in Activity transitions. If false, the ViewGroup won't transition, only its children. If true, the entire ViewGroup will transition together. |