ViewGroupKt
public final class ViewGroupKt
Summary
Public methods |
|
|---|---|
static final boolean |
Returns |
static final void |
Performs the given action on each view in this view group. |
static final void |
forEachIndexed(Performs the given action on each view in this view group, providing its sequential index. |
static final @NonNull View |
Returns the view at |
static final @NonNull Sequence<@NonNull View> |
getChildren(@NonNull ViewGroup receiver)Returns a |
static final @NonNull Sequence<@NonNull View> |
getDescendants(@NonNull ViewGroup receiver)Returns a |
static final @NonNull IntRange |
getIndices(@NonNull ViewGroup receiver)Returns an |
static final int |
Returns the number of views in this view group. |
static final boolean |
Returns true if this view group contains no views. |
static final boolean |
isNotEmpty(@NonNull ViewGroup receiver)Returns true if this view group contains one or more views. |
static final @NonNull Iterator<@NonNull View> |
Returns a |
static final void |
minusAssign(@NonNull ViewGroup receiver, @NonNull View view)Removes |
static final void |
plusAssign(@NonNull ViewGroup receiver, @NonNull View view)Adds |
static final void |
setMargins(@NonNull ViewGroup.MarginLayoutParams receiver, @Px int size)Sets the margins in the ViewGroup's MarginLayoutParams. |
static final void |
updateMargins(Updates the margins in the |
static final void |
updateMarginsRelative(Updates the relative margins in the ViewGroup's MarginLayoutParams. |
Public methods
contains
public static final boolean contains(@NonNull ViewGroup receiver, @NonNull View view)
Returns true if view is found in this view group.
forEach
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
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
public static final @NonNull View get(@NonNull ViewGroup receiver, int index)
Returns the view at index.
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if index is less than 0 or greater than or equal to the count. |
getChildren
public static final @NonNull Sequence<@NonNull View> getChildren(@NonNull ViewGroup receiver)
Returns a Sequence over the immediate child views in this view group.
| See also | |
|---|---|
allViews |
|
descendants |
getDescendants
public static final @NonNull Sequence<@NonNull View> getDescendants(@NonNull ViewGroup receiver)
Returns a Sequence 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) }
}getIndices
public static final @NonNull IntRange getIndices(@NonNull ViewGroup receiver)
Returns an IntRange 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
public static final int getSize(@NonNull ViewGroup receiver)
Returns the number of views in this view group.
isEmpty
public static final boolean isEmpty(@NonNull ViewGroup receiver)
Returns true if this view group contains no views.
isNotEmpty
public static final boolean isNotEmpty(@NonNull ViewGroup receiver)
Returns true if this view group contains one or more views.
iterator
public static final @NonNull Iterator<@NonNull View> iterator(@NonNull ViewGroup receiver)
Returns a MutableIterator over the views in this view group.
minusAssign
public static final void minusAssign(@NonNull ViewGroup receiver, @NonNull View view)
Removes view from this view group.
plusAssign
public static final void plusAssign(@NonNull ViewGroup receiver, @NonNull View view)
Adds view to this view group.
setMargins
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 | |
|---|---|
setMargins |
updateMargins
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 ViewGroup's ViewGroup.MarginLayoutParams. This version of the method allows using named parameters to just set one or more axes.
| See also | |
|---|---|
setMargins |
updateMarginsRelative
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 for more information.
| See also | |
|---|---|
setMargins |