2
我正在研究一个涉及使用随机生成的图像序列对图像进行动画处理的项目。这里的代码,我现在不工作(或至少它不会出现工作):使用AnimationDrawable无法正常工作的Android图像动画
/**
* Method to display the current sequence
* TODO make an animation for the screen to use
*/
public void displaySeq() {
ad = new AnimationDrawable();
int j = 0;
for(Integer i : sequence) {
switch(i)
{
case Constants.RED:
System.out.printf("%d - RED\n", j);
ad.addFrame(resources.getDrawable(R.drawable.red_circle), 500);
break;
case Constants.BLUE:
System.out.printf("%d - BLUE\n", j);
ad.addFrame(resources.getDrawable(R.drawable.blue_circle), 500);
break;
case Constants.GREEN:
System.out.printf("%d - GREEN\n", j);
ad.addFrame(resources.getDrawable(R.drawable.green_circle), 500);
break;
case Constants.YELLOW:
System.out.printf("%d - YELLOW\n", j);
ad.addFrame(resources.getDrawable(R.drawable.yellow_circle), 500);
break;
default:
System.out.printf("%d - bad color: %d\n", j, i);
ad.addFrame(resources.getDrawable(R.drawable.black_circle), 500);
}
j++;
}
// add a black circle to the end of the animation
ad.addFrame(resources.getDrawable(R.drawable.black_circle), 500);
System.out.println("Number of frames: " + ad.getNumberOfFrames());
indicator.setBackground(ad);
indicator.post(new Starter());
}
class Starter implements Runnable {
@Override
public void run() {
ad.start();
}
}
当我运行应用程序并调用此方法,我看到logcat的打印输出,但是指示灯没有得到动画。任何想法出了什么问题?