-
-
Save z8888q/9994682 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//inside a fragment. If in an Activity you could use findViewById(Window.ID_ANDROID_CONTENT); | |
getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() | |
{ | |
@Override | |
public void onGlobalLayout() | |
{ | |
//do something like measure a view etc | |
View content = getWindow().findViewById(Window.ID_ANDROID_CONTENT); | |
Log.d("DISPLAY", content.getWidth() + " x " + content.getHeight()); | |
//we only wanted the first call back so now remove | |
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) | |
getView().getViewTreeObserver().removeGlobalOnLayoutListener(this); | |
else | |
getView().getViewTreeObserver().removeOnGlobalLayoutListener(this); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment