本文介绍了AnimationDrawable编程无动画列表XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个情况下,我希望显示图像的动态列表动画。我想用AnimationDrawable用于此目的,但不幸的是我坚持... :(我的code是为
ImageView的地球=(ImageView的)findViewById(R.id.globe);
AnimationDrawable动画=新AnimationDrawable();
animation.setOneShot(真正的);
资源RES = this.getResources();
而(来自以下; =到){
字符串名称=globe_+的String.Format(%03D,从);
INT globeId = res.getIdentifier(姓名,绘制,
this.getPackageName());
animation.addFrame(res.getDrawable(globeId),200);
从++;
}
globe.setBackgroundDrawable(动画);
globe.post(新的Runnable(){
@覆盖
公共无效的run(){
animation.start();
}
});
解决方案
我只是做了 animation.start()
循环后,并从一个可运行调用的函数,它工作
同时(从< =到){
字符串名称=globe_+的String.Format(%03D,从);
INT globeId = res.getIdentifier(姓名,绘制,
this.getPackageName());
animation.addFrame(res.getDrawable(globeId),200);
从++;
}
globe.setBackgroundDrawable(动画);
animation.start()
I am in a situation where I want to display animation from dynamic list of images. I want to use AnimationDrawable for this purpose, but unfortunately I am stuck... :( my code is as
ImageView globe = (ImageView) findViewById(R.id.globe);
AnimationDrawable animation = new AnimationDrawable();
animation.setOneShot(true);
Resources res = this.getResources();
while (from <= to) {
String name = "globe_" + String.format("%03d", from);
int globeId = res.getIdentifier(name, "drawable",
this.getPackageName());
animation.addFrame(res.getDrawable(globeId), 200);
from++;
}
globe.setBackgroundDrawable(animation);
globe.post(new Runnable(){
@Override
public void run() {
animation.start();
}
});
解决方案
I just did animation.start()
after the loop and called the function from a runnable and it worked
while (from <= to) {
String name = "globe_" + String.format("%03d", from);
int globeId = res.getIdentifier(name, "drawable",
this.getPackageName());
animation.addFrame(res.getDrawable(globeId), 200);
from++;
}
globe.setBackgroundDrawable(animation);
animation.start()
这篇关于AnimationDrawable编程无动画列表XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!