Last active
March 10, 2017 07:40
-
-
Save snadjafi/520d7ac377ecdfd69c98 to your computer and use it in GitHub Desktop.
TreeObserver example
This file contains 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
mView.getViewTreeObserver().addOnGlobalLayoutListener( | |
new ViewTreeObserver.OnGlobalLayoutListener() { | |
public void onGlobalLayout() { | |
int width = mView.getWidth(); | |
int height = mView.getHeight(); | |
if (mView.getViewTreeObserver().isAlive()) { | |
// remove this layout listener | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
mView.getViewTreeObserver() | |
.removeOnGlobalLayoutListener(this); | |
} else { | |
mView.getViewTreeObserver() | |
.removeGlobalOnLayoutListener(this); | |
} | |
} | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment