0

さまざまなオブジェクトのセットをさまざまな期間で次々にアニメーション化するにはどうすればよいですか?

JAVAコード:

ImageButton home = (ImageButton)findViewById(R.id.homeicon);
ImageButton settings = (ImageButton)findViewById(R.id.settingsicon); 

Animation alpha_anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
home.startAnimation(alpha_anim);
settings.startAnimation(alpha_anim);

アニメーションファイル:

<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha="0.9"
android:duration="8000" /> 

誰かが私を助けることができますか?

4

3 に答える 3

1

最初のアニメーションにかかる時間だけ、2番目のアニメーションに遅延を追加できます。これはあなたのニーズに対して十分に正確ではないかもしれないことを理解してください、そうでなければあなたはAnimationListenerのルートに行く必要があるかもしれません

home.startAnimation(alpha_anim);
alpha_anim.setStartOffset(8000);
settings.startAnimation(alpha_anim);
于 2012-06-26T08:25:28.443 に答える
1

最初のレイアウトをアニメーション化する必要がある画面が1つあり、その画面が終了したらすぐに、2番目のレイアウトでアニメーションを開始したいと思いました。

だから私はhandlerその時にそうするためにこのように使用していました

Handler handler = new Handler(); // create Handler object
handler.post(homeRun);
Runnable homeRun = new Runnable() { // create runnable to start home anim
    public void run() {
        home.startAnimation(alpha_anim);
        handler.postDelayed(settingsRun, 1000); // start setting anim after the time the home takes to animate
    }
};

Runnable setingsRun = new Runnable() { // runnable to start settings anim
    public void run() {
        settings.startAnimation(alpha_anim);
    }
};
于 2012-06-26T08:54:25.067 に答える
0

次々に実行したい場合は、このコードを使用できます。リスナーを使用することで、アニメーションが確実に終了します。

animation.setDuration(8000);
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationEnd(Animation animation) {
            animation.setDuration(6000);
                                 animation.setAnimationListener(null);
            settings.startAnimation(animation);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationStart(Animation animation) {
        }

    });
    home.startAnimation(alpha_anim);
于 2012-06-26T09:09:44.733 に答える