Why we use ViewTreeObserver#addOnGlobalLayoutListener()
问题 Why do we use ViewTreeObserver , please can anyone explain it? In below code creditsView is TextView object. By this whole code I understand that "this is to hide some text based on condition", but only thing is why we are using ViewTreeObserver ? mainLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int heightDiff = mainLayout.getRootView().getHeight() - mainLayout.getHeight(); if (heightDiff > 100)