1

私は Android アプリに取り組んでおり、メイン/ランチャー画面 (アプリを最初に起動したときに表示される画面) で、バックグラウンドで簡単なアニメーションを表示したいと考えています。具体的には、現在、ウィンドウの中央にいくつかのボタンがあり、背景にはいくつかの小さな星があり、他のすべての背後で、画面の左上から右下へのループ変換アニメーションを実行しています。これはインタラクティブではなく、終了すると単純に繰り返されます。私はこれらの星を 9 つ持っていますが、それほど大きくはありません。ただし、アプリを実行しようとすると (これは主にエミュレーターで発生しますが、携帯電話でも発生しますが、頻度は低くなります)、次のようなメッセージが表示されます。

I/Choreographer(  632): Skipped 33 frames!  The application may be doing too much work on its main thread.

それが実際に行っていることは、私の星を一列に並べようとしていて、同時に動いているようです. アニメーションを開始すると、それらは互いにオフセットして実行されます。つまり、星は約 0.5 秒ごとに移動しますが、フレームをスキップすると、星が整列するように並べられます (いくつかから始まり、最終的にはすべての星で終わります)。星) がまったく同時にアニメーションを開始および終了しています。大量の星が背景を同じ速度で同時に移動しているため、これは非常にばかげているように見えます。それらをすべて同時に正確に移動させることは、オフセットで実行させるよりもプロセッサの作業が少ないと推測しています。

メイン スレッド以外では UI アクティビティを実行できないことはわかっていますが、これは少しばかげているように思えます。私がしているのは、アプリのバックグラウンドで単純なアニメーションを繰り返すことだけであり、それは「やりすぎ」です。それで、私のアニメーションが実際に本来あるべきように見えるように、作業を減らすアニメーションを行う方法はありますか? 私は単純なゲームを書こうとしていますが、反復可能な非インタラクティブな方法でいくつかのオブジェクトをアニメーション化することさえできなければ、インタラクティブなゲームをどのように処理できるか想像できません. しかし、私は Android でインタラクティブなゲームをプレイしたことがあるので、何かが欠けているに違いありません。誰にもヒントはありますか?

PS here は、アニメーションを実行するために使用しているコードです。
アニメーション コード:

public static Animation _runAnimation(Activity ctx, View target) {
      Animation animation = AnimationUtils.loadAnimation(ctx, R.anim.slide_right);
      animation.setFillAfter(true);
      target.startAnimation(animation);
      return animation;
    }

アニメーションのレイアウト: (slide_right.xml)

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" >
    <translate android:fromXDelta="-20%p" android:toXDelta="100%p" android:duration="2000" android:repeatCount="infinite" />
    <translate android:fromYDelta="-20%p" android:toYDelta="100%p" android:duration="2000" android:repeatCount="infinite" />
    <!--rotate android:pivotX="0" android:toDegrees="360" android:duration="2000" android:repeatCount="10000" /-->//this doesn't cause the stars to spin in place, it rotates them around a point. 

</set>

実際の通話:

public Activity _launcher = this; //the activity
public Handler handler = new Handler(); //a handler
handler.postDelayed(new Runnable() { 
                 public void run() { 
                     _runAnimation(_launcher, findViewById(R.id.star1)); 
                 } 
            }, 10);
handler.postDelayed(new Runnable() { 
                 public void run() { 
                     _runAnimation(_launcher, findViewById(R.id.star2)); 
                 } 
            }, 700);
handler.postDelayed(new Runnable() { 
             public void run() { 
                 _runAnimation(_launcher, findViewById(R.id.star3)); 
             } 
        }, 1600); 
handler.postDelayed(new Runnable() { 
             public void run() { 
                 _runAnimation(_launcher, findViewById(R.id.star4)); 
             } 
        }, 2500); 
handler.postDelayed(new Runnable() { 
             public void run() { 
                 _runAnimation(_launcher, findViewById(R.id.star5)); 
             } 
        }, 3300);
handler.postDelayed(new Runnable() { 
             public void run() { 
                 _runAnimation(_launcher, findViewById(R.id.star6)); 
             } 
        }, 3700);

handler.postDelayed(new Runnable() { 
             public void run() { 
                 _runAnimation(_launcher, findViewById(R.id.star7)); 
             } 
        }, 4400);

handler.postDelayed(new Runnable() { 
             public void run() { 
                 _runAnimation(_launcher, findViewById(R.id.star8)); 
             } 
        }, 5300);

handler.postDelayed(new Runnable() { 
             public void run() { 
                 _runAnimation(_launcher, findViewById(R.id.star9)); 
             } 
        }, 5800);
4

0 に答える 0