How to get height of a view in Kotlin?


I am trying to get height of a view in onCreate method but I couldn't find any way to remove OnGlobalLayoutListener.

In Java (working):

containerLayout.getViewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {  
  public void onGlobalLayout() {  
  int width  = layout.getMeasuredWidth();
  int height = layout.getMeasuredHeight();


In Kotlin (not excepting “this”):

containerLayout.viewTreeObserver.addOnGlobalLayoutListener {
Toast.makeText(applicationContext, "size is "+ containerLayout.height,Toast.LENGTH_LONG).show()

Is there any reference or example for this problem? Thanks.