@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); int size = Math.min(width, height); setMeasuredDimension(size, size); }This code example overrides onMeasure to set the dimensions of the View to always be square, by grabbing the smallest dimension between height and width, and using that as the height and width of the View. Package Library: This method is part of the android.view package library.