Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android imageview scaletype not working for AnimationDrawable

I have a imageview that fills my entire screen and i downloaded images from url into my sdcard, I am using AnimationDrawable to show these images as slideshow in the imageview. But however I try my Images are loosing their aspect ratio, the images appear stretched. I have tried all the scaletype's for my imageview, but no use. Here is my code:

    AnimationDrawable animation = new AnimationDrawable();
    File cacheDir = AlRimal.getDataFolder(Main_Load.this);
    File cacheFile = new File(cacheDir, "file_1.jpg");
    Drawable d = Drawable.createFromPath(cacheFile.getPath());
    Bitmap bitmap = BitmapFactory.decodeFile(cacheFile.getPath());
    animation.addFrame(d, 5000);
    animation.addFrame(d, 5000);
    animation.addFrame(d, 5000);
    animation.setOneShot(false);
    animation.setExitFadeDuration(500);
    animation.setEnterFadeDuration(500);
    animationImg.setScaleType(ScaleType.FIT_CENTER);//All possibilities have been tried
    animationImg.setBackgroundDrawable(animation);
    animation.start();

The resoulution of my images are : 2048*1536

like image 818
sharath Avatar asked Feb 11 '23 09:02

sharath


2 Answers

The ScaleType was not being set because, image in the ImageView was set as the background. When I changed it to the source it worked.

like image 124
sharath Avatar answered Mar 05 '23 18:03

sharath


instead of

animationImg.setBackgroundDrawable(animation);

try to use

animationImg.setImageDrawable(animation);
like image 35
Kastriot Dreshaj Avatar answered Mar 05 '23 17:03

Kastriot Dreshaj