Skip to content

Instantly share code, notes, and snippets.

@douzifly
Created June 13, 2014 03:40
Show Gist options
  • Save douzifly/833d9b9568f29f0a2953 to your computer and use it in GitHub Desktop.
Save douzifly/833d9b9568f29f0a2953 to your computer and use it in GitHub Desktop.
postOnLayoutFinished
public static void postOnLayoutFinished(final View v, final Runnable r) {
if (v == null || r == null) {
throw new NullPointerException();
}
v.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
r.run();
v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment