So to make an image square the following code works:
public class SquareImageView extends ImageView {
...
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
setMeasuredDimension(width, width);
}
...
}
So my question is:
If I understand correctly we have to call super.onMeasure
so that the object can figure out its width and height. But when we pass in the setMeasuredDimension
the width
both as height and width to make the image square does the Android scale the image?
Any kind of such changes are they scaled properly? Or the best approach is to already have the resource square e.g. from some photo editing tool