我从运行时获取此代码的错误 -
ImageView couponImage = (ImageView) findViewById(R.id.couponImg);
couponImage.setBackgroundResource(R.drawable.coupon);
AnimationDrawable couponAnimation = (AnimationDrawable)
couponImage.getBackground();
couponAnimation.start();
“引起:java.lang.ClassCastException:android.graphics.drawable.BitmapDrawable”>错误。 但如果我不使用“AnimationDrawable couponAnimation”eclipse抱怨。
答案 0 :(得分:1)
ImageView couponImage = (ImageView) findViewById(R.id.couponImg);
AnimationDrawable couponImg =
(AnimationDrawable) getResources().getDrawable(R.drawable.couponImg);
couponImg.setBackgroundDrawable(couponImg);
couponImg.start();