I wanted to make items of my grid view perfect squares. I used the method suggested by this answer and it worked well.
Following is the code (Overridden onMeasure
method of grid view item)
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
Now I want to make the height of the items 1.2 times bigger than the item width. So, I modified the code like below.
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, (int) (widthMeasureSpec * 1.2));
}
But, the items become very long and can't even fit into the screen anymore.
Surprisingly, if I set the heightMeasureSpec to a lesser value than widthMeasureSpec, still the item height gets larger than the width. Following code makes items taller.
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, (int) (widthMeasureSpec * 0.5));
}
Can someone explain this behavior? Is there any way I can achieve what I want?