Skip to content

Instantly share code, notes, and snippets.

@truongngoclinh
Created May 3, 2017 07:31
Show Gist options
  • Save truongngoclinh/f180c582a79b5e4bdd62ede4f3748d9f to your computer and use it in GitHub Desktop.
Save truongngoclinh/f180c582a79b5e4bdd62ede4f3748d9f to your computer and use it in GitHub Desktop.
Catch view changes
final LinearLayout layout = (LinearLayout) findViewById(R.id.YOUR_VIEW_ID);
ViewTreeObserver vto = layout.getViewTreeObserver();
vto.addOnGlobalLayoutListener (new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int width = layout.getMeasuredWidth();
int height = layout.getMeasuredHeight();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment