Skip to content

Instantly share code, notes, and snippets.

@nalitzis
Created July 12, 2013 20:27
Show Gist options
  • Save nalitzis/5987554 to your computer and use it in GitHub Desktop.
Save nalitzis/5987554 to your computer and use it in GitHub Desktop.
get view size through View.MeasureSpec
private Pair<Integer,Integer> measureButton(){
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.EXACTLY);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.EXACTLY);
mButton.measure(widthMeasureSpec, heightMeasureSpec);
int h = mButton.getMeasuredHeight();
int w = mButton.getMeasuredWidth();
Log.d(TAG, "height of button is :"+h+", width is :"+w);
return new Pair<Integer, Integer>(w,h);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment