Making GridView items square

android, gridview

Solution

There is a simpler solution when GridView columns are stretched. Just override the onMeasure of the GridView item layout with...

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}

Problem

I would like the items of my `GridView` to be square. There are 2 columns and the items width is `fill_parent` (e.g. they take as much horizontal space as possible. The items are custom views. How do I make the items height to be equal to their variable width?

Original source

Related problems