我需要使用旋转功能进行图像视图。所以我看着Android开发者site。并使用他们的代码。但不知何故,我得到一个错误。ImageView在Android中的旋转
错误:java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
我有这些代码:
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();
在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>
请帮助我。从android的网站我得到的代码,但他们的代码不起作用。也许问题出在我的spin_animation.xml文件中。
refresh.getBackground
返回StateListDrawable
我想。
对不起,我编辑了我的答案.. – KrishnaJ