@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mHeightRatio > 0.0) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = (int) (width * mHeightRatio); super.setMeasuredDimension(width, height); } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }