Android 如何使用毕加索加载动画列表?

Android 如何使用毕加索加载动画列表?,android,picasso,animationdrawable,Android,Picasso,Animationdrawable,将图像加载到我的应用程序时出现内存不足异常。我集成了毕加索来加载图像,但下面的代码不能用于AnimationDrawable的动画列表。动画为空: Picasso.with(this).load(R.drawable.qtidle).into(qtSelectButton); qtIdleAnimation = (AnimationDrawable)qtSelectButton.getDrawable(); if (qtIdleAnimation != null) qtIdleAnima

将图像加载到我的应用程序时出现内存不足异常。我集成了毕加索来加载图像,但下面的代码不能用于AnimationDrawable的动画列表。动画为空:

Picasso.with(this).load(R.drawable.qtidle).into(qtSelectButton);
qtIdleAnimation = (AnimationDrawable)qtSelectButton.getDrawable();
if (qtIdleAnimation != null)
    qtIdleAnimation.start();
如果我在不使用毕加索的情况下使用此代码,则AnimationDrawable可以工作:

qtIdleAnimation = new AnimationDrawable();
qtIdleAnimation.setOneShot(false);
for (int i = 1; i <= 7; i++) {
    int qtidleId = res.getIdentifier("qtidle" + i, "drawable", this.getPackageName());
    qtIdleAnimation.addFrame(res.getDrawable(qtidleId), 100);
}
qtSelectButton.setImageDrawable(qtIdleAnimation);
if (qtIdleAnimation != null)
    qtIdleAnimation.start();
qtIdleAnimation=new AnimationDrawable();
qtileanimation.setOneShot(false);

对于(int i=1;i毕加索不能直接将
xml
文件中定义的加载到视图中。但是模仿毕加索自己的基本行为并不太困难:

1.以编程方式定义和启动动画,就像您所做的那样,但在异步任务内,以避免内存不足异常

Resources res = this.getResources();
ImageView imageView = findViewById(R.id.image_view);
int[] ids = new int[] {R.drawable.img1, R.drawable.img2, R.drawable.img3};
创建以下内容的子容器:

2.如果您的可绘图文件比视图大,请仅以所需分辨率加载可绘图文件以节省内存

不要直接添加可绘制图形:

a.addFrame(res.getDrawable(id), 100);
添加它的缩小版本:

a.addFrame(new BitmapDrawable(res, decodeSampledBitmapFromResource(res, id, w, h));

其中
w
h
是视图的维度,
decodeSampledBitmapFromResource()
是Android官方文档中定义的一种方法()

您找到了什么吗?请回复。对不起,我一直没有找到它,然后我放弃了这个项目。
a.addFrame(res.getDrawable(id), 100);
a.addFrame(new BitmapDrawable(res, decodeSampledBitmapFromResource(res, id, w, h));