Load Image With Glide and Change Aspect Ratio
One way around is to use a Image view with 16:9 ratio .
public class CustomImageView extends AppCompatImageView {
public CustomImageView(Context context) {
super(context);
}
public CustomImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
int height=(width * 9) / 16;
setMeasuredDimension(width, height);
}
}
This will make a ImageView
with hard code ratio of 16/9
. You can use Custom attributes for it to make it more flexible.