Android Ktx Wait for Layout Change Callback/Event

July 25, 2018
Execute when view is rendered
view.updateLayoutParams {
    this.width = newWidth
}

Log.d(TAG, "oldWidth=${view.width}")

view.doOnLayout {
    Log.d(TAG, "newWidth=${view.width}")
}

doOnLayout

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.

doOnNextLayout

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

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.