ランダムに生成された一連の画像を使用して画像をアニメーション化するプロジェクトに取り組んでいます。これが私が今持っているコードで、動作していません(または少なくとも動作していないようです):
/**
* 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 に出力が表示されますが、インジケーターはアニメーション化されません。何がうまくいかないのですか?