OneShotPreDrawListener
class OneShotPreDrawListener : OnPreDrawListener, OnAttachStateChangeListener
kotlin.Any | |
↳ | androidx.core.view.OneShotPreDrawListener |
An OnPreDrawListener that will remove itself after one OnPreDraw call. Typical usage is:
<code>
OneShotPreDrawListener.add(view, () -> { view.doSomething(); })
</code>
The onPreDraw always returns true.
The listener will also remove itself from the ViewTreeObserver when the view is detached from the view hierarchy. In that case, the Runnable will never be executed.
Summary
Public methods |
|
---|---|
static OneShotPreDrawListener |
Creates a OneShotPreDrawListener and adds it to view's ViewTreeObserver. |
Boolean | |
Unit | |
Unit | |
Unit |
Removes the listener from the ViewTreeObserver. |
Public methods
add
@NonNull static fun add(@NonNull view: View, @NonNull runnable: Runnable): OneShotPreDrawListener
Creates a OneShotPreDrawListener and adds it to view's ViewTreeObserver.
Parameters | |
---|---|
view |
View: The view whose ViewTreeObserver the OnPreDrawListener should listen. |
runnable |
View: The Runnable to execute in the OnPreDraw (once) |
Return | |
---|---|
OneShotPreDrawListener: The added OneShotPreDrawListener. It can be removed prior to the onPreDraw by calling removeListener() . |
onPreDraw
fun onPreDraw(): Boolean
removeListener
fun removeListener(): Unit
Removes the listener from the ViewTreeObserver. This is useful to call if the callback should be removed prior to onPreDraw()
.