@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (getChildCount() != 1) {
throw new IllegalStateException("ProportionalLayout requires exactly one child");
}
final View child = getChildAt(0);
measureChild(child, widthMeasureSpec, heightMeasureSpec);
final int childWidth = child.getMeasuredWidth();
final int childHeight = child.getMeasuredHeight();
final int width;
final int height;
if (mDirection == Direction.heightToWidth) {
width = Math.round(childHeight * mRatio);
height = childHeight;
} else {
width = childWidth;
height = Math.round(childWidth * mRatio);
}
measureChild(child,
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
setMeasuredDimension(
resolveSize(width, widthMeasureSpec), resolveSize(height, heightMeasureSpec));
}