0

ロードする必要がある 4 つの画像があります。1 つのアニメーションを再生し、500 ミリ秒待機し、別のアニメーションを再生し、500 ミリ秒待機するなどです。アニメーションが行うのは、アルファを 255 から 0 に変更してから 255 に戻すことだけです。4 つのすべての imageView でそのアニメーションが必要です。

私は現在2つの問題を抱えています。

1.) すべての画像が同時に再生されます。
2.) 次にメソッドが呼び出されたときに、アニメーションが機能しません。

public void computerLights()
{

    ImageView green = (ImageView)findViewById(R.id.imgViewGreen);
    ImageView red = (ImageView)findViewById(R.id.imgViewRed);
    ImageView blue = (ImageView)findViewById(R.id.imgViewBlue);
    ImageView yellow = (ImageView)findViewById(R.id.imgViewYellow);

    AlphaAnimation transparency = new AlphaAnimation(1, 0);

    transparency.setDuration(500);
    transparency.start();
    green.startAnimation(transparency);
    red.startAnimation(transparency);
    blue.startAnimation(transparency);
    yellow.startAnimation(transparency);
}
4

1 に答える 1

0

これが最も洗練されたソリューションかどうかはわかりませんが、500 ミリ秒間隔でメッセージを送信できるハンドラーを使用すると、これを非常に簡単に実現できます。

private int mLights = new ArrayList<ImageView>();
private int mCurrentLightIdx = 0;
private Handler mAnimationHandler = new Handler(){

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);

        ImageView currentLightIdx = mLights.get(currentLight);

        AlphaAnimation transparency = new AlphaAnimation(1, 0);

        transparency.setDuration(500);
        transparency.start();
        currentLight.startAnimation(transparency);

        currentLightIdx++;
        if(currentLightIdx < mLights.size()){
            this.sendMessageDelayed(new Message(), 500);
    }
};

public void computerLights()
{

    ImageView green = (ImageView)findViewById(R.id.imgViewGreen);
    ImageView red = (ImageView)findViewById(R.id.imgViewRed);
    ImageView blue = (ImageView)findViewById(R.id.imgViewBlue);
    ImageView yellow = (ImageView)findViewById(R.id.imgViewYellow);

    mLights.add(green);
    mLights.add(red);
    mLights.add(blue);
    mLights.add(yellow);

    mAnimationHandler.sendMessage(new Message());
}

最初のメッセージが送信された後、すべてのアニメーションが開始されるまで、ハンドラーは 500 ミリ秒ごとにメッセージを送信し続けます。

于 2013-04-07T04:06:17.937 に答える