PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

[FIXED] how can I resize gif with custom height and width in android?

 July 18, 2022     android, android-ion, gif, imageview     No comments   

Issue

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));

Solution

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;
            }
        });
    }
});


Answered By - winchester
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing