Skip to content

Instantly share code, notes, and snippets.

@denisokvrn
Created November 10, 2016 14:26
Show Gist options
  • Save denisokvrn/4476efabdddc668d705ffe18e66955b8 to your computer and use it in GitHub Desktop.
Save denisokvrn/4476efabdddc668d705ffe18e66955b8 to your computer and use it in GitHub Desktop.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (maxWidth > 0 && maxWidth < MeasureSpec.getSize(widthMeasureSpec)) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.AT_MOST);
} else if (minWidth > 0 && minWidth > MeasureSpec.getSize(widthMeasureSpec)) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(minWidth, MeasureSpec.EXACTLY);
}
if (maxHeight > 0 && maxHeight < MeasureSpec.getSize(heightMeasureSpec)) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST);
} else if (minHeight > 0 && minHeight > MeasureSpec.getSize(widthMeasureSpec)) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(minHeight, MeasureSpec.EXACTLY);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment