Skip to content

Instantly share code, notes, and snippets.

@mikeseif
Created July 11, 2014 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeseif/4ff5c3f77268b2cbe29b to your computer and use it in GitHub Desktop.
Save mikeseif/4ff5c3f77268b2cbe29b to your computer and use it in GitHub Desktop.
Making an Android view / layout square
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int size = 0;
int width = getMeasuredWidth();
int height = getMeasuredHeight();
if (width > height) {
size = height;
} else {
size = width;
}
setMeasuredDimension(size, size);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment