Created
July 11, 2014 01:48
-
-
Save mikeseif/4ff5c3f77268b2cbe29b to your computer and use it in GitHub Desktop.
Making an Android view / layout square
This file contains 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
@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