How to Make a gridview Item in perfect square ?

With this answer we no need to specify the height and width to gridview.
We can easily manage gridview item with proper square with this customsquare view.
Below I add the customsquare view code and also how to implement in xml file.

xml :
<customsquareView
android:id=”@+id/imggridimage”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:adjustViewBounds=”true”
android:scaleType=”centerCrop” />
customsquare.java

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

public class customsquareView extends ImageView
{

public customsquareView(final Context context)
{
super(context);
}

public customsquareView(final Context context, final AttributeSet attrs)
{
super(context, attrs);
}

public customsquareView(final Context context, final AttributeSet attrs, final int defStyle)
{
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec)
{
final int gridwidth= getDefaultSize(getSuggestedMinimumWidth(),widthMeasureSpec);
setMeasuredDimension(gridwidth, gridwidth);
}

@Override
protected void onSizeChanged(final int width, final int height, final int oldwidth, final int oldheight)
{
super.onSizeChanged(width, width, oldwidth, oldheight);
}
}