android imageview scaletype 不适用于 AnimationDrawable

标签 android android-layout imageview android-animation

我有一个填满整个屏幕的 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/

相关文章:

android - 计算谷歌地图v2中4条边的坐标

android - 在垂直方向显示的 AlertDialog 按钮中

android - 设备屏幕尺寸对缩放的 ImageViews 有奇怪的影响

android - 在eclipse中制作android图标的透明背景

android - R8 去除反射所需的 Kotlin 伴生对象

java - 将带有毫秒和时区的字符串转换为日期

Android:高级文本绘制(分栏、固定高度、分页)。如何?

android - 样式属性在合并标签上不起作用

android - 如何在多行TextView的末尾插入ImageView?

java - 如何在 ListView 中无延迟地从网络下载图像?