Open muayyad-alsadi opened 11 years ago
I've solved that via extending SmartImageView with this class:
public class AspectRatioImageView extends SmartImageView {
public AspectRatioImageView(Context context) {
super(context);
}
public AspectRatioImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AspectRatioImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (getDrawable() != null) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = width * getDrawable().getIntrinsicHeight() / getDrawable().getIntrinsicWidth();
setMeasuredDimension(width, height);
} else {
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
}
}
}
@alex-oleshkevich does it work even when the size of the image is not know because the image is still to come. and will it get fixed when downloading is finished.
yes
Hello, trying this class, but the remote images that have different sizes are not scalling(for instance there are portrait images and landscape ones). Is this just for internal drawables or it should work for remote images? Thank you
hi,
this way suggest a simple class that extends from imageview but this does not work here since we don't know width until we fetch/download the image
http://stackoverflow.com/questions/18077325/scale-image-to-fill-imageview-width-and-keep-aspect-ratio
any suggestion ?