Skip to content

Instantly share code, notes, and snippets.

@Jawnnypoo
Created December 10, 2014 18:20
Show Gist options
  • Save Jawnnypoo/1b6b2d035628f387a2c5 to your computer and use it in GitHub Desktop.
Save Jawnnypoo/1b6b2d035628f387a2c5 to your computer and use it in GitHub Desktop.
Example of setting an onPreDrawListener on a view
final View view = findViewById(R.id.view_id);
view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
view.getViewTreeObserver().removeOnPreDrawListener(this);
//Do the things you want to do. Return true if you want to draw that frame, otherwise return false
return false;
}
});
@sarath-rp
Copy link

Could you write its explanation that why is it used?

It will be used to draw the children of a view group related to its parent width and height.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment