ViewKt

public final class ViewKt


Summary

Public fields

final @NonNull Sequence<@NonNull View>

Returns a Sequence over this view and its descendants recursively.

final @NonNull Sequence<@NonNull ViewParent>

Returns a Sequence of the parent chain of this view by repeatedly calling View.getParent.

final boolean

Returns true when this view's visibility is View.GONE, false otherwise.

final boolean

Returns true when this view's visibility is View.INVISIBLE, false otherwise.

final boolean

Returns true when this view's visibility is View.VISIBLE, false otherwise.

final int

Returns the bottom margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

final int

Returns the end margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

final int

Returns the left margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

final int

Returns the right margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

final int

Returns the start margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

final int

Returns the top margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Public methods

static final void
ViewKt.doOnAttach(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewUnit> action
)

Performs the given action when this view is attached to a window.

static final void
ViewKt.doOnDetach(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewUnit> action
)

Performs the given action when this view is detached from a window.

static final void
ViewKt.doOnLayout(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewUnit> action
)

Performs the given action when this view is laid out.

static final void
ViewKt.doOnNextLayout(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewUnit> action
)

Performs the given action when this view is next laid out.

static final @NonNull OneShotPreDrawListener
ViewKt.doOnPreDraw(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewUnit> action
)

Performs the given action when the view tree is about to be drawn.

static final @NonNull Bitmap

Return a Bitmap representation of this View.

static final @NonNull Runnable
ViewKt.postDelayed(
    @NonNull View receiver,
    long delayInMillis,
    @NonNull Function0<Unit> action
)

Version of View.postDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

static final @RequiresApi(value = "16") @NonNull Runnable
ViewKt.postOnAnimationDelayed(
    @NonNull View receiver,
    long delayInMillis,
    @NonNull Function0<Unit> action
)

Version of View.postOnAnimationDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

static final void
ViewKt.setPadding(@NonNull View receiver, @Px int size)

Sets the view's padding.

static final void
ViewKt.updateLayoutParams(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewGroup.LayoutParamsUnit> block
)

Executes block with the View's layoutParams and reassigns the layoutParams with the updated version.

static final void
<T extends ViewGroup.LayoutParams> ViewKt.updateLayoutParamsTyped(
    @NonNull View receiver,
    @NonNull Function1<@NonNull T, Unit> block
)

Executes block with a typed version of the View's layoutParams and reassigns the layoutParams with the updated version.

static final void
ViewKt.updatePadding(
    @NonNull View receiver,
    @Px int left,
    @Px int top,
    @Px int right,
    @Px int bottom
)

Updates this view's padding.

static final @RequiresApi(value = "17") void
ViewKt.updatePaddingRelative(
    @NonNull View receiver,
    @Px int start,
    @Px int top,
    @Px int end,
    @Px int bottom
)

Updates this view's relative padding.

Public fields

allViews

@NonNull
public final @NonNull Sequence<@NonNull ViewallViews

Returns a Sequence over this view and its descendants recursively. This is a depth-first traversal similar to View.findViewById. A view with no children will return a single-element sequence of itself.

See also
descendants

ancestors

@NonNull
public final @NonNull Sequence<@NonNull ViewParentancestors

Returns a Sequence of the parent chain of this view by repeatedly calling View.getParent. An unattached view will return a zero-element sequence.

See also
descendants

isGone

@NonNull
public final boolean isGone

Returns true when this view's visibility is View.GONE, false otherwise.

if (view.isGone) {
// Behavior...
}

Setting this property to true sets the visibility to View.GONE, false to View.VISIBLE.

view.isGone = true

isInvisible

@NonNull
public final boolean isInvisible

Returns true when this view's visibility is View.INVISIBLE, false otherwise.

if (view.isInvisible) {
// Behavior...
}

Setting this property to true sets the visibility to View.INVISIBLE, false to View.VISIBLE.

view.isInvisible = true

isVisible

@NonNull
public final boolean isVisible

Returns true when this view's visibility is View.VISIBLE, false otherwise.

if (view.isVisible) {
// Behavior...
}

Setting this property to true sets the visibility to View.VISIBLE, false to View.GONE.

view.isVisible = true

marginBottom

@NonNull
public final int marginBottom

Returns the bottom margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

marginEnd

@NonNull
public final int marginEnd

Returns the end margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

marginLeft

@NonNull
public final int marginLeft

Returns the left margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

marginRight

@NonNull
public final int marginRight

Returns the right margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

marginStart

@NonNull
public final int marginStart

Returns the start margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

marginTop

@NonNull
public final int marginTop

Returns the top margin if this view's LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Public methods

ViewKt.doOnAttach

@NonNull
public static final void ViewKt.doOnAttach(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewUnit> action
)

Performs the given action when this view is attached to a window. If the view is already attached to a window the action will be performed immediately, otherwise the action will be performed after the view is next attached.

The action will only be invoked once, and any listeners will then be removed.

See also
doOnDetach

ViewKt.doOnDetach

@NonNull
public static final void ViewKt.doOnDetach(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewUnit> action
)

Performs the given action when this view is detached from a window. If the view is not attached to a window the action will be performed immediately, otherwise the action will be performed after the view is detached from its current window.

The action will only be invoked once, and any listeners will then be removed.

See also
doOnAttach

ViewKt.doOnLayout

@NonNull
public static final void ViewKt.doOnLayout(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewUnit> action
)

Performs the given action when this view is laid out. If the view has been laid out and it has not requested a layout, the action will be performed straight away, otherwise the action will be performed after the view is next laid out.

The action will only be invoked once on the next layout and then removed.

See also
doOnNextLayout

ViewKt.doOnNextLayout

@NonNull
public static final void ViewKt.doOnNextLayout(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewUnit> action
)

Performs the given action when this view is next laid out.

The action will only be invoked once on the next layout and then removed.

See also
doOnLayout

ViewKt.doOnPreDraw

@NonNull
public static final OneShotPreDrawListener ViewKt.doOnPreDraw(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewUnit> action
)

Performs the given action when the view tree is about to be drawn.

The action will only be invoked once prior to the next draw and then removed.

ViewKt.drawToBitmap

@NonNull
public static final Bitmap ViewKt.drawToBitmap(@NonNull View receiver, @NonNull Bitmap.Config config)

Return a Bitmap representation of this View.

The resulting bitmap will be the same width and height as this view's current layout dimensions. This does not take into account any transformations such as scale or translation.

Note, this will use the software rendering pipeline to draw the view to the bitmap. This may result with different drawing to what is rendered on a hardware accelerated canvas (such as the device screen).

If this view has not been laid out this method will throw a IllegalStateException.

Parameters
@NonNull Bitmap.Config config

Bitmap config of the desired bitmap. Defaults to Bitmap.Config.ARGB_8888.

ViewKt.postDelayed

@NonNull
public static final Runnable ViewKt.postDelayed(
    @NonNull View receiver,
    long delayInMillis,
    @NonNull Function0<Unit> action
)

Version of View.postDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

view.postDelayed(200) {
doSomething()
}
Returns
Runnable

the created Runnable

ViewKt.postOnAnimationDelayed

@RequiresApi(value = "16")
@NonNull
public static final @RequiresApi(value = "16") Runnable ViewKt.postOnAnimationDelayed(
    @NonNull View receiver,
    long delayInMillis,
    @NonNull Function0<Unit> action
)

Version of View.postOnAnimationDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

view.postOnAnimationDelayed(16) {
doSomething()
}
Returns
@RequiresApi(value = "16") Runnable

the created Runnable

ViewKt.setPadding

@NonNull
public static final void ViewKt.setPadding(@NonNull View receiver, @Px int size)

Sets the view's padding. This version of the method sets all axes to the provided size.

See also
setPadding

ViewKt.updateLayoutParams

@NonNull
public static final void ViewKt.updateLayoutParams(
    @NonNull View receiver,
    @NonNull Function1<@NonNull ViewGroup.LayoutParamsUnit> block
)

Executes block with the View's layoutParams and reassigns the layoutParams with the updated version.

See also