Ich muss eine Bildansicht mit Rotationsfunktion machen. Also schaute ich auf die Android-Entwickler site. Und benutzte ihre Codes. Aber irgendwie bekomme ich einen Fehler.ImageView mit Drehung in Android
Fehler: java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
Ich habe diese Codes:
ImageView refresh = (ImageView)findViewById(R.id.refresh_devices_button);
refresh.setBackgroundResource(R.drawable.spin_animation); // The IDE says that it may produce null pointer exception
AnimationDrawable frameAnimation = (AnimationDrawable) refresh.getBackground();
frameAnimation.start();
In spin_animation.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<animation-list android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/scan_1" android:duration="50" />
<item android:drawable="@drawable/scan_2" android:duration="50" />
<item android:drawable="@drawable/scan_3" android:duration="50" />
<item android:drawable="@drawable/scan_4" android:duration="50" />
<item android:drawable="@drawable/scan_5" android:duration="50" />
</animation-list>
</selector>
Bitte mir helfen. Von Android-Website bekomme ich die Codes, aber ihre Codes funktionieren nicht. Vielleicht ist das Problem mit meiner spin_animation.xml-Datei.
refresh.getBackground
liefert StateListDrawable
ich denke.
Sorry, ich habe meine Antwort bearbeitet. – KrishnaJ