Skip to content

Instantly share code, notes, and snippets.

@vicky7230
Forked from omorandi/android_get_view_size.java
Created November 26, 2015 07:20
Show Gist options
  • Save vicky7230/e7941d800ac51f96e4fb to your computer and use it in GitHub Desktop.
Save vicky7230/e7941d800ac51f96e4fb to your computer and use it in GitHub Desktop.
Android: get the actual size of a match_parent/wrap_content view
view.post(new Runnable() {
@Override
public void run() {
int width = view.getWidth();
int height = view.getHeight();
//do something cool with width and height
}
});
//the runnable is executed only after the view is completely laid out
//less problematic than using ViewTreeObserver.addOnGlobalLayoutListener
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment