Last active
August 29, 2015 13:56
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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