开发者

How to change annimation drawabale

Currently I work on a project where I need to change an animationdrawable using a handler, so here is my code

ImageView imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.wait);
  imageView = (ImageView) findViewById(R.id.imageView);
  final AnimationDrawable drawable = new AnimationDrawable();
  drawable.addFrame(getResources.getDrawable(R.drawable.go_0), 80);
  drawable.addFrame(getResources.getDrawable(R.drawable.go_1), 80);
  drawable.addFrame(getResources.getDrawable(R.drawable.go_2), 80);
  drawable.addFrame(getResources.getDrawable(R.drawable.go_3), 80);
  drawable.addFrame(getResources.getDrawable(R.drawable.go_4), 80);
  imageView.setBackgroundDrawable(drawable);
  imageView.post(new Runnable() {
    public void run() {
     // TODO Auto-generated method stub
     drawable.start();
   }
  });
}
public boolean handleMessage(Message msg) {

  if(msg.what = 10){
    final AnimationDrawable final AnimationDrawable drawable = new AnimationDrawable();
    drawable.addFrame(getResources.getDrawable(R.drawable.back_0), 80);
    drawable.addFrame(getResources.getDrawable(R.drawable.back_1), 80);
    drawable.addFrame(getResources.getDrawable(R.drawable.back_2), 80);
    drawable.addFrame(getResources.getDrawable(R.drawable.back_3), 80);
    drawable.addFrame(getResources.getDrawable(R.drawable.back_4), 80);
    imageView.setBackgroundDrawable(drawable);
    imageView.post(new Runnable() {
      public开发者_开发百科 void run() {
       // TODO Auto-generated method stub
       drawable.start();
     }
    }); 
  }
}

But the animation don't change? Do you know what's the problem? help me please:(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜