0

I am using Koush/Ion library to load gif from internet into imageview but I cannot resize the gifs aspectly, upon calling resize function, gif becomes still

so my question is, is there any way I can resize gif aspectly in android ?

here's my calculation to get aspect height and width of image if that helps

final int newWidth = deviceWidth;
final int newHeight = (int) ((int) newWidth * (imageHeight / imageWidth));
winchester
  • 65
  • 2
  • 12

2 Answers2

2

I think I finally found the solution, First scale image with FIT_XY and then set 'newHeight' as the height of image view

imageView.setScaleType(ScaleType.FIT_XY);
imageView.getLayoutParams().height = newHeight; 

Code Snippet

Ion.with(imageView)
    .animateGif(AnimateGifMode.ANIMATE)
    .load(imgUrl)
    .setCallback(new FutureCallback < ImageView > () {

    @SuppressLint("NewApi")
    @Override
    public void onCompleted(Exception arg0,
    ImageView arg1) {

        imageView.getViewTreeObserver().addOnPreDrawListener(
        new ViewTreeObserver.OnPreDrawListener() {
            public boolean onPreDraw() {

                imageView.getViewTreeObserver()
                    .removeOnPreDrawListener(this);

                imageView.setScaleType(ScaleType.FIT_XY);
                imageView.getLayoutParams().height = newHeight;

                return true;
            }
        });
    }
});
winchester
  • 65
  • 2
  • 12
0

You can resize a gif in android programatically. When you do so the gif does not animate as it becomes a normal Image. In order to resize the gif and animate it, the only suggestion that I can give you is to use online resizing tools like

Later save the resized gif in your assets folder and then call that using the Ion library which you use like this

Ion.with(yourImageView).load("yourAssetFolder/yourGifImage.gif")
Bullionist
  • 2,070
  • 3
  • 25
  • 42