无法在Studio中启动动画(ClassCastException:StateListDrawable到AnimationDrawable)

时间:2019-06-01 23:39:07

标签: java android android-animation android-drawable classcastexception

我想开始播放动画。我在res / drawable中定义了动画:

<animation-list android:id="@+id/flying_around" android:oneshot="false">
<item android:drawable="@drawable/ricky_flames" android:duration="50" />
<item android:drawable="@drawable/ricky_flames_1" android:duration="50" />
<item android:drawable="@drawable/ricky_flames_2" android:duration="50" />
<item android:drawable="@drawable/ricky_flames_3" android:duration="50" />
<item android:drawable="@drawable/ricky_flames_4" android:duration="50" />
</animation-list>

,当我几次单击文本后(在textView的setOnClickListener函数中),我尝试在onCreate方法中启动此动画:

tutorialText.setVisibility(View.GONE);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.ricky_flying_animation));
startEngine = (AnimationDrawable) imageView.getDrawable();   
startEngine.start();

这是错误:

java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.graphics.drawable.AnimationDrawable

0 个答案:

没有答案