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() {
@Override
public void onGlobalLayout() {
containerLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int width = layout.getMeasuredWidth();
int height = layout.getMeasuredHeight();
}
});
In Kotlin (not excepting “this”):
containerLayout.viewTreeObserver.addOnGlobalLayoutListener {
containerLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
Toast.makeText(applicationContext, "size is "+ containerLayout.height,Toast.LENGTH_LONG).show()
}
Is there any reference or example for this problem? Thanks.