mView.afterMeasured {
// inside this block the view is completely drawn
// you can get view's height/width, it.height / it.width
}
Under the hood
inline fun View.afterMeasured(crossinline f: View.() -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
if (measuredHeight > 0 && measuredWidth > 0) {
viewTreeObserver.removeOnGlobalLayoutListener(this)
f()
}
}
})
}