Skip to content

Instantly share code, notes, and snippets.

@vincent1086
Created November 8, 2016 09:15
Show Gist options
  • Save vincent1086/a2c686a497d37862b785473c30f55e59 to your computer and use it in GitHub Desktop.
Save vincent1086/a2c686a497d37862b785473c30f55e59 to your computer and use it in GitHub Desktop.
Android onMeasure() get size
public static int resolveSize(int size, int measureSpec) {
int result = size;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
switch (specMode) {
case MeasureSpec.UNSPECIFIED:
result = size;
break;
case MeasureSpec.AT_MOST:
result = Math.min(size, specSize);
break;
case MeasureSpec.EXACTLY:
result = specSize;
break;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment