我有一个填满整个屏幕的 ImageView ,我从 url 下载图像到我的 sdcard,我正在使用 AnimationDrawable 将这些图像显示为 ImageView 中的幻灯片。但无论我如何尝试,我的图像都失去了它们的纵横比,图像看起来被拉伸(stretch)了。我已经为我的 imageview 尝试了所有的 scaletype,但没有用。这是我的代码:
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();
我图片的分辨率是:2048*1536
最佳答案
未设置 ScaleType
,因为 ImageView
中的图像已设置为背景。当我将其更改为源时,它起作用了。
关于android imageview scaletype 不适用于 AnimationDrawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27395282/