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) 时,Eclipse 将android:src参数设置为我选择的图像。更改android:srcandroid:drawable解决问题。

于 2012-11-01T12:03:51.170 回答