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
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.
instead of
animationImg.setBackgroundDrawable(animation);
try to use
animationImg.setImageDrawable(animation);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With