Skip to content

Instantly share code, notes, and snippets.

@LouisCAD
Created October 11, 2016 07:32
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 LouisCAD/fa4febfe1f72d16315e2ddf0210845fc to your computer and use it in GitHub Desktop.
Save LouisCAD/fa4febfe1f72d16315e2ddf0210845fc to your computer and use it in GitHub Desktop.
Makes any view square
/**
* Ensures the view is square by making it the size of the smallest side.
*/
@Override
protected final void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int size = Math.min(getMeasuredWidth(), getMeasuredHeight());
setMeasuredDimension(size, size);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment