2

をクリックすると、AnimationDrawable を使用してフレーム間アニメーションを表示しようとしていますImageView。しかし、私のアニメーションは、 をクリックしたときに一度だけ発生しますImageView。アニメーションにはxmlを使用しています。

アニメーション 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/scorepopup1" android:duration="100" />
  <item android:drawable="@drawable/scorepopup2" android:duration="100" />
  <item android:drawable="@drawable/scorepopup3" android:duration="100" />
  <item android:drawable="@drawable/scorepopup4" android:duration="100" />
  <item android:drawable="@drawable/invipopup" android:duration="100" />

</animation-list>

ボタンとアニメーション画像のコンテナーの xml は次のとおりです。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="70dp"
    android:layout_height="50dp"
    android:layout_alignParentRight="true" 
    android:layout_margin="5dp">

    <ImageView
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:background="@drawable/bd"
    android:layout_margin="10dp"
    android:onClick="checkGem" 
    android:contentDescription="bd"/>


    <ImageView
        android:id="@+id/scorePopup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp" />
</LinearLayout>

checkGem メソッド:

ImageView popup1 =  (ImageView) findViewById(R.id.scorePopup);

popup1.setBackgroundResource(R.drawable.popup1_animation);
AnimationDrawable frameAnimation2 = (AnimationDrawable) 

popup1.getBackground();
frameAnimation2.start();

私の問題は、アニメーションが一度しか表示されないことですが、クリックするたびにアニメーションを表示したいです。何か案は?

4

1 に答える 1

4

コールの直前にのバックグラウンドでstop()コールを発信します。ImageViewAnimationDrawablestart()

//...
AnimationDrawable frameAnimation2 = (AnimationDrawable) popup1.getBackground();
frameAnimation2.stop();
frameAnimation2.start();

最初にクリックするImageViewとアニメーションが実行されますが、最後にはまだ実行されていると思われる状態になります。その状態では、呼び出しstart()は単純に無視されます。stop()メソッドはその状態を「リセット」AnimationDrawableし、最初から再び実行されます。

于 2013-01-31T19:36:09.377 に答える