Skip to content

Instantly share code, notes, and snippets.

@bugraoral
Last active August 29, 2015 13:56
Show Gist options
  • Save bugraoral/8824122 to your computer and use it in GitHub Desktop.
Save bugraoral/8824122 to your computer and use it in GitHub Desktop.
Used for getting layout measurements when layout has not been calculated and drawn.
final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();
if(viewTreeObserver.isAlive()){
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void onGlobalLayout() {
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
int height = view.getHeight();
int heightMeasured = descriptionTextView.getMeasuredHeight();
//do your thing
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment