Я следил за приложением Google, как использовать AnimationDrawable с ImageView. Вы можете найти его здесь: http://developer.android.com/guide/topics/graphics/drawable-animation.htmljava.lang.ClassCastException: android.graphics.drawable.ColorDrawable не может быть передан в android.graphics.drawable.AnimationDrawable
image.setBackgroundResource(R.drawable.run_animation);
frameAnimation = (AnimationDrawable) image.getDrawable();
frameAnimation.start();
вытяжки файла run_animation:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/iv1"
android:duration="500" />
<item
android:drawable="@drawable/iv2"
android:duration="500" />
<item
android:drawable="@drawable/iv3"
android:duration="500" />
<item
android:drawable="@drawable/iv4"
android:duration="500" />
</animation-list>
После выполнения я receciving этой ошибки на LogCat
java.lang.ClassCastException: android.graphics.drawable.ColorDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
пожалуйста, помогите мне.
Вы можете увидеть подобную нить [здесь] (http://stackoverflow.com/questions/27951712/android-animationdrawable-cast -ошибка). Поскольку @TheOneX сказал в этом потоке, попробуйте getDrawable(), а не getBackground() – Raghavendra
Он не работает – kashyap
Неужели вы пытаетесь с getDrawable(), чем image.getBackground()? – Raghavendra