Android ImageView的ScaleType对AnimationDrawable无效

4

我有一个ImageView,它填满了整个屏幕,我从url下载图像到我的SD卡中,我正在使用AnimationDrawable将这些图像显示为幻灯片放映在ImageView中。但是,无论如何尝试,我的图片都失去了它们的纵横比,图像会出现拉伸的情况。我已经尝试了所有的ImageView的缩放类型,但是没有用。这是我的代码:

    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。
2个回答

5

由于ImageView中的图像设置为背景,导致ScaleType未被设置。当我将其更改为源时,它就可以工作了。


3

替换为

animationImg.setBackground(animation);

尝试使用

animationImg.setImageDrawable(animation);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接