android-smart-image-view icon indicating copy to clipboard operation
android-smart-image-view copied to clipboard

away to fill width and keep aspect ratio in height

Open muayyad-alsadi opened this issue 12 years ago • 4 comments

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 ?

muayyad-alsadi avatar Nov 17 '13 14:11 muayyad-alsadi

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 avatar Dec 11 '13 23:12 alex-oleshkevich

@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.

muayyad-alsadi avatar Dec 22 '13 09:12 muayyad-alsadi

yes

alex-oleshkevich avatar Dec 22 '13 10:12 alex-oleshkevich

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

codepixely avatar Jan 31 '14 16:01 codepixely