我正在从事一个项目,该项目涉及使用随机生成的图像序列对图像进行动画处理。这是我现在不工作的代码(或者至少它似乎不工作):
/**
* 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 中看到打印输出,但指示器没有动画。任何想法出了什么问题?