# ViewGroupKt

Added in 1.1.0

*** ** * ** ***


```
public final class ViewGroupKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final boolean` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).contains(android.view.View)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view)` Returns `true` if `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.ViewGroup).contains(android.view.View)` is found in this view group. |
| `static final void` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).forEach(kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> action )` Performs the given action on each view in this view group. |
| `static final void` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).forEachIndexed(kotlin.Function2)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver, @https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> action )` Performs the given action on each view in this view group, providing its sequential index. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).get(kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver, int index)` Returns the view at `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.ViewGroup).get(kotlin.Int)`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html>` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).getChildren()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver)` Returns a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html` over the immediate child views in this view group. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html>` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).getDescendants()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver)` Returns a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html` over the child views in this view group recursively. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).getIndices()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver)` Returns an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html` of the valid indices for the children of this view group. |
| `static final int` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).getSize()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver)` Returns the number of views in this view group. |
| `static final boolean` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).isEmpty()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver)` Returns true if this view group contains no views. |
| `static final boolean` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).isNotEmpty()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver)` Returns true if this view group contains one or more views. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Iterator.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html>` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).iterator()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver)` Returns a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-iterator/index.html` over the views in this view group. |
| `static final void` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).minusAssign(android.view.View)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view)` Removes `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.ViewGroup).minusAssign(android.view.View)` from this view group. |
| `static final void` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup).plusAssign(android.view.View)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view)` Adds `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.ViewGroup).plusAssign(android.view.View)` to this view group. |
| `static final void` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup.MarginLayoutParams).setMargins(kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html receiver, @https://developer.android.com/reference/androidx/annotation/Px int size)` Sets the margins in the ViewGroup's MarginLayoutParams. |
| `static final void` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup.MarginLayoutParams).updateMargins(kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html receiver, @https://developer.android.com/reference/androidx/annotation/Px int left, @https://developer.android.com/reference/androidx/annotation/Px int top, @https://developer.android.com/reference/androidx/annotation/Px int right, @https://developer.android.com/reference/androidx/annotation/Px int bottom )` Updates the margins in the `https://developer.android.com/reference/android/view/ViewGroup.html`'s `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html`. |
| `static final void` | `https://developer.android.com/reference/androidx/core/view/ViewGroupKt#(android.view.ViewGroup.MarginLayoutParams).updateMarginsRelative(kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html receiver, @https://developer.android.com/reference/androidx/annotation/Px int start, @https://developer.android.com/reference/androidx/annotation/Px int top, @https://developer.android.com/reference/androidx/annotation/Px int end, @https://developer.android.com/reference/androidx/annotation/Px int bottom )` Updates the relative margins in the ViewGroup's MarginLayoutParams. |

## Public methods

### contains

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

```
public static final boolean contains(@NonNull ViewGroup receiver, @NonNull View view)
```

Returns `true` if `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.ViewGroup).contains(android.view.View)` is found in this view group.

### forEach

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

```
public static final void forEach(
    @NonNull ViewGroup receiver,
    @NonNull Function1<@NonNull View, Unit> action
)
```

Performs the given action on each view in this view group.

### forEachIndexed

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

```
public static final void forEachIndexed(
    @NonNull ViewGroup receiver,
    @NonNull Function2<@NonNull Integer, @NonNull View, Unit> action
)
```

Performs the given action on each view in this view group, providing its sequential index.

### get

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

```
public static final @NonNull View get(@NonNull ViewGroup receiver, int index)
```

Returns the view at `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.ViewGroup).get(kotlin.Int)`.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if index is less than 0 or greater than or equal to the count. |

### getChildren

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

```
public static final @NonNull Sequence<@NonNull View> getChildren(@NonNull ViewGroup receiver)
```

Returns a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html` over the immediate child views in this view group.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.View).allViews()` |   |
| `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.ViewGroup).descendants()` |   |

### getDescendants

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/view/ViewGroup.kt+symbol:descendants) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/core#1.5.0)

```
public static final @NonNull Sequence<@NonNull View> getDescendants(@NonNull ViewGroup receiver)
```

Returns a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html` over the child views in this view group recursively.

This performs a depth-first traversal. A view with no children will return a zero-element sequence.

For example, to efficiently filter views within the hierarchy using a predicate:

```
fun ViewGroup.findViewTreeIterator(predicate: (View) -> Boolean): Sequence<View> {
    return sequenceOf(this)
        .plus(descendantsTree)
        .filter { predicate(it) }
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.View).allViews()` |   |
| `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.ViewGroup).children()` |   |
| `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.View).ancestors()` |   |

### getIndices

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/view/ViewGroup.kt+symbol:indices) Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/core#1.8.0)

```
public static final @NonNull IntRange getIndices(@NonNull ViewGroup receiver)
```

Returns an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html` of the valid indices for the children of this view group.

This can be used for looping:

```
for (i in viewGroup.indices.reversed) {
  if (viewGroup[i] is SomeView) {
    viewGroup.removeViewAt(i)
  }
}
```

Or to determine if an index is valid:

```
if (2 in viewGroup.indices) {
  // Do something…
}
```

### getSize

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

```
public static final int getSize(@NonNull ViewGroup receiver)
```

Returns the number of views in this view group.

### isEmpty

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

```
public static final boolean isEmpty(@NonNull ViewGroup receiver)
```

Returns true if this view group contains no views.

### isNotEmpty

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

```
public static final boolean isNotEmpty(@NonNull ViewGroup receiver)
```

Returns true if this view group contains one or more views.

### iterator

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

```
public static final @NonNull Iterator<@NonNull View> iterator(@NonNull ViewGroup receiver)
```

Returns a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-iterator/index.html` over the views in this view group.

### minusAssign

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

```
public static final void minusAssign(@NonNull ViewGroup receiver, @NonNull View view)
```

Removes `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.ViewGroup).minusAssign(android.view.View)` from this view group.

### plusAssign

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

```
public static final void plusAssign(@NonNull ViewGroup receiver, @NonNull View view)
```

Adds `https://developer.android.com/reference/androidx/core/view/package-summary#(android.view.ViewGroup).plusAssign(android.view.View)` to this view group.

### setMargins

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

```
public static final void setMargins(@NonNull ViewGroup.MarginLayoutParams receiver, @Px int size)
```

Sets the margins in the ViewGroup's MarginLayoutParams. This version of the method sets all axes to the provided size.

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMargins(int, int, int, int)` |   |

### updateMargins

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

```
public static final void updateMargins(
    @NonNull ViewGroup.MarginLayoutParams receiver,
    @Px int left,
    @Px int top,
    @Px int right,
    @Px int bottom
)
```

Updates the margins in the `https://developer.android.com/reference/android/view/ViewGroup.html`'s `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html`. This version of the method allows using named parameters to just set one or more axes.

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMargins(int, int, int, int)` |   |

### updateMarginsRelative

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

```
public static final void updateMarginsRelative(
    @NonNull ViewGroup.MarginLayoutParams receiver,
    @Px int start,
    @Px int top,
    @Px int end,
    @Px int bottom
)
```

Updates the relative margins in the ViewGroup's MarginLayoutParams. This version of the method allows using named parameters to just set one or more axes.

Note that this inline method references platform APIs added in API 17 and may raise runtime verification warnings on earlier platforms. See Chromium's guide to [Class Verification Failures](https://chromium.googlesource.com/chromium/src/+/HEAD/build/android/docs/class_verification_failures.md) for more information.

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMargins(int, int, int, int)` |   |