2

ランダムに生成された一連の画像を使用して画像をアニメーション化するプロジェクトに取り組んでいます。これが私が今持っているコードで、動作していません(または少なくとも動作していないようです):

/**
 * 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 に出力が表示されますが、インジケーターはアニメーション化されません。何がうまくいかないのですか?

4

1 に答える 1

0

私は実際に問題を理解しました。XML ファイルのエラーが原因でした。基本的に、Eclipse で layout.xml ファイルを作成し、ImageView( indicator)を追加するとandroid:src、選択したイメージに Eclipse がパラメーターを設定します。に変更android:srcするとandroid:drawable問題が解決しました。

于 2012-11-01T12:03:51.170 に答える