2011-12-24 2 views
0

は私がanimationdrawable

runtime-
ImageView couponImage = (ImageView) findViewById(R.id.couponImg); 
    couponImage.setBackgroundResource(R.drawable.coupon); 

    AnimationDrawable couponAnimation = (AnimationDrawable)  
couponImage.getBackground(); 
    couponAnimation.start(); 

から、このコードにエラーが発生します。 しかし、私が "AnimationDrawable couponAnimation"を使用しないと、Eclipseは不平を言う。

答えて

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

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

couponImg.setBackgroundDrawable(couponImg); 

couponImg.start();