Stay organized with collections Save and categorize content based on your preferences.

ViewKt

public final class ViewKt


Summary

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 Sequence<@NonNull View>

Returns a Sequence over this view and its descendants recursively.

static final @NonNull Sequence<@NonNull ViewParent>

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

static final int

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

static final int

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

static final int

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

static final int

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

static final int

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

static final int

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

static final boolean

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

static final boolean

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

static final boolean

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

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 @NonNull Runnable
@RequiresApi(value = 16)
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.setGone(@NonNull View receiver, boolean isGone)

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

static final void
ViewKt.setInvisible(@NonNull View receiver, boolean isInvisible)

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

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

Sets the view's padding.

static final void
ViewKt.setVisible(@NonNull View receiver, boolean isVisible)

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

static final void

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,
    @ExtensionFunctionType @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 void
@RequiresApi(value = 17)
ViewKt.updatePaddingRelative(
    @NonNull View receiver,
    @Px int start,
    @Px int top,
    @Px int end,
    @Px int bottom
)

Updates this view's relative padding.

Public methods

ViewKt.doOnAttach

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

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

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

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

public 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.

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

ViewKt.drawToBitmap

public static final @NonNull 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.getAllViews

public static final @NonNull Sequence<@NonNull ViewViewKt.getAllViews(@NonNull View receiver)

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

ViewKt.getAncestors

public static final @NonNull Sequence<@NonNull ViewParentViewKt.getAncestors(@NonNull View receiver)

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

ViewKt.getMarginBottom

public static final int ViewKt.getMarginBottom(@NonNull View receiver)

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

ViewKt.getMarginEnd

public static final int ViewKt.getMarginEnd(@NonNull View receiver)

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

ViewKt.getMarginLeft

public static final int ViewKt.getMarginLeft(@NonNull View receiver)

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

ViewKt.getMarginRight

public static final int ViewKt.getMarginRight(@NonNull View receiver)

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

ViewKt.getMarginStart

public static final int ViewKt.getMarginStart(@NonNull View receiver)

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

ViewKt.getMarginTop

public static final int ViewKt.getMarginTop(@NonNull View receiver)

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

ViewKt.isGone

public static final boolean ViewKt.isGone(@NonNull View receiver)

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

ViewKt.isInvisible

public static final boolean ViewKt.isInvisible(@NonNull View receiver)

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

ViewKt.isVisible

public static final boolean ViewKt.isVisible(@NonNull View receiver)

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

ViewKt.postDelayed

public 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.

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

the created Runnable

ViewKt.postOnAnimationDelayed

@RequiresApi(value = 16)
public static final @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.

view.postOnAnimationDelayed(16) {
doSomething()
}
Returns
@NonNull Runnable

the created Runnable

ViewKt.setGone

public static final void ViewKt.setGone(@NonNull View receiver, 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

ViewKt.setInvisible

public static final void ViewKt.setInvisible(@NonNull View receiver, 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

ViewKt.setPadding

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.setVisible

public static final void ViewKt.setVisible(@NonNull View receiver, 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

ViewKt.updateLayoutParams

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

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

ViewKt.updateLayoutParamsTyped

public static final void <T extends ViewGroup.LayoutParams> ViewKt.updateLayoutParamsTyped(
    @NonNull View receiver,
    @ExtensionFunctionType @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.

ViewKt.updatePadding

public 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. This version of the method allows using named parameters to just set one or more axes.

See also
setPadding

ViewKt.updatePaddingRelative

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

Updates this view's relative padding. 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.