使用Android的处理程序动画 [英] Android animation using Handler

查看:131
本文介绍了使用Android的处理程序动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在它使用一个处理程序来定期更新/无效的安卓游戏工作。在handleMessage()函数,有些情况可能会产生,我想在固定的数量,以动画的操作。我用另一种处理这个固定的时间动画。然后,code似乎进入僵局。什么是处理这个问题的最好方法?使用内部FOR循环另一个线程Thread.sleep()方法?在code第二处理程序:

 私人AnimateHandler mAnimateHandler =新AnimateHandler();   类AnimateHandler扩展了Handler {
       长delayMillis;       @覆盖
       公共无效的handleMessage(消息MSG){
           如果(指数< config.planeWidth){
               更新();
               无效();
               sendMessageDelayed(obtainMessage(0),delayMillis);
           }其他stopAnimation();
       }       公共无效动画(长delayMillis){
           this.delayMillis = delayMillis;
           this.removeMessages(0);
           sendMessageDelayed(obtainMessage(0),delayMillis);
       }
   };


解决方案

原来其他code会导致问题。

I work on an android game which uses an handler to update/invalidate routinely. In handleMessage(), some condition may incur an operation that I want to animate in fixed counts. I use another handler for this fixed time animation. Then the code seems entering deadlock. What is the best way to handle this? Use another thread and Thread.sleep() inside FOR loop? The code for the second handler:

   private AnimateHandler mAnimateHandler = new AnimateHandler();

   class AnimateHandler extends Handler {
       long delayMillis;

       @Override
       public void handleMessage(Message msg) {
           if(index < config.planeWidth) {
               update();
               invalidate();
               sendMessageDelayed(obtainMessage(0), delayMillis);
           } else stopAnimation();
       }

       public void animate(long delayMillis) {
           this.delayMillis = delayMillis;
           this.removeMessages(0);
           sendMessageDelayed(obtainMessage(0), delayMillis);
       }
   };

解决方案

It turns out other code causes the problem.

这篇关于使用Android的处理程序动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆