Skip to content

Instantly share code, notes, and snippets.

@fada21
Last active August 29, 2015 14:00
Show Gist options
  • Save fada21/11366705 to your computer and use it in GitHub Desktop.
Save fada21/11366705 to your computer and use it in GitHub Desktop.
ViewTreeObserver.OnGlobalLayoutListener() handling
{
final ViewTreeObserver viewTreeObserver = someView.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
viewTreeObserver.removeGlobalOnLayoutListener(this);
} else {
viewTreeObserver.removeOnGlobalLayoutListener(this);
}
doThings();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment