-1

Thread と AnimationDrawable で使用しているイメージ シーケンスを繰り返す必要がありますが、継続的に機能していません。次のアクティビティがボタン クリック イベントによって開始されるまで、このアニメーションを停止したくありません。

ここに私のJavaコードがあります:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);{

final ImageView splashImage=(ImageView)findViewById(R.id.heartFunction);
     splashImage.setBackgroundResource(R.drawable.slide_right);
  splashAnimation = (AnimationDrawable) splashImage.getBackground();
}




public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    if ( isFocused ) {
        //isFocused = false;

        splashAnimation.start();
        var=false;
        new Thread(new Runnable() {
        public void run() {
            try {
                Thread.sleep(SPLASH_DISPLAY_LENGTH);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).start();
}

slide_right.xml:-

<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">

<item android:drawable="@drawable/heartcolored0" android:duration="200" />
<item android:drawable="@drawable/heartcolored2" android:duration="200" />
<item android:drawable="@drawable/heartcolored4" android:duration="200" />
<item android:drawable="@drawable/heartcolored5" android:duration="200" />
<item android:drawable="@drawable/heartcolored6" android:duration="200" />
<item android:drawable="@drawable/heartcolored7" android:duration="200" />
<item android:drawable="@drawable/heartcolored8" android:duration="200" />
<item android:drawable="@drawable/heartcolored9" android:duration="200" />
<item android:drawable="@drawable/heartcolored10" android:duration="200" />
<item android:drawable="@drawable/heartcolored11" android:duration="200" />
<item android:drawable="@drawable/heartcolored12" android:duration="200" />
<item android:drawable="@drawable/heartcolored13" android:duration="200" />

</animation-list>
4

1 に答える 1

2

アニメーションを継続的に実行したい場合は、設定する必要がありますandroid:oneshot="false"

前に一度だけ駆け抜けろって言ってたな。

画面をクリックして次のアクティビティに移動するまでアニメーションを実行したい場合。onWindowFocusChanged 関数でアニメーションを開始する

@Override
public void onWindowFocusChanged(boolean hasFocus){
    splashanimation.start();
}

次に、onTouchEvent を使用してタッチをキャッチし、新しいアクティビティを開始して、古いアクティビティを終了します。

@Override
public boolean onTouchEvent(MotionEvent event){
     if (event.getAction() == MotionEvent.ACTION_DOWN) {
          Intent i = new Intent(Anim.this, Main.class);
          startActivity(i);
          finish();
     }
return true;
}

これがお役に立てば幸いです。あなたの質問は非常に読みにくい/理解するのが難しいです。

于 2010-07-26T16:33:12.377 に答える