animationdrawable

时间:2011-12-24 04:18:48

标签: android-layout

  

我从运行时获取此代码的错误 -

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抱怨。

1 个答案:

答案 0 :(得分:1)

ImageView couponImage = (ImageView) findViewById(R.id.couponImg);

AnimationDrawable couponImg = 
           (AnimationDrawable) getResources().getDrawable(R.drawable.couponImg);

couponImg.setBackgroundDrawable(couponImg);

couponImg.start();