How would I go implementing a fixed aspect ratio View
? I\'d like to have items with 1:1 aspect ratio in a GridView
. I think it\'s better to subclas
Simply override onSizeChanged
and calculate ratio there.
Formula for aspect ratio is:
newHeight = original_height / original_width x new_width
this would give you something like that:
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
//3:5 ratio
float RATIO = 5/3;
setLayoutParams(new LayoutParams((int)RATIO * w, w));
}
hope this helps!