containerLayout.viewTreeObserver.addOnGlobalLayoutListener(object: OnGlobalLayoutListener { override fun onGlobalLayout() { // your code here. `this` should work } })