GridViewのCell などのサイズを比率で指定する

GridView は、横幅が自動計算されるため、比率を合わせるには、設定時に計算する必要がある。

FrameLayout を入れていた場合は、以下のように onMeasure を オーバーライドし、height を再計算する。
xml の 属性に、layout_height_ratio="0.8" のように指定すればよい。
xml を編集中にも、プレビューに反映され確認できます。

public class CustomFrameLayout extends FrameLayout {

    public CustomFrameLayout(Context context) {
        this(context, null);
    }

    public CustomFrameLayout (Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomFrameLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        _ratio = attrs.getAttributeFloatValue (null, "layout_heightRatio", 1.0f);
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        final int width = MeasureSpec.getSize (widthMeasureSpec);
        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        final int height = (int)(width * _ratio);

        final int hSpec = MeasureSpec.makeMeasureSpec (height, widthMode);

        super.onMeasure(widthMeasureSpec, hSpec);
    }

    final float _ratio;
}