代码之家  ›  专栏  ›  技术社区  ›  mobibob

为什么我的Android动画不能调用onAnimationEnd?

  •  1
  • mobibob  · 技术社区  · 14 年前

    我的动画工作,当线程结束时,下一个屏幕的意图激发,但它不会从动画结束时激发。我把所有的 AnimationListener's

    public class PromoActivity extends Activity implements AnimationListener {
        protected boolean _active = true;
        protected int _splashTime = 5000; // time to display the splash screen in ms
    
        private static final float ROTATE_FROM = 0.0f;
        private static final float ROTATE_TO = -10.0f * 360.0f;// 3.141592654f * 32.0f;
        private static final String TAG = "PromoActivity";
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Thread promoThread = new Thread() {
                @Override
                public void run() {
                    try {
                        ImageView favicon = (ImageView) findViewById(R.id.favicon);
    
                        RotateAnimation r; // = new RotateAnimation(ROTATE_FROM, ROTATE_TO);
                        r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                        r.setDuration((long) 2*1500);
                        favicon.startAnimation(r);
    
                        RotateAnimation q;
                        q = new RotateAnimation(ROTATE_FROM, -ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                        q.setDuration((long) 2*1500);
                        q.setRepeatCount(0);
                        TextView mobiText = (TextView) findViewById(R.id.logotext_mobi);
                        mobiText.startAnimation(q);
    
                        TextView dawgText = (TextView) findViewById(R.id.logotext_bob);
                        dawgText.startAnimation(q);
    
                        int waited = 0;
                        while (_active && (waited < _splashTime)) {
                            sleep(100);
                            if (_active) {
                                waited += 100;
                            }
                        }
                    } catch (InterruptedException ex) {
    
                    } finally {
                        finish();
                        startActivity(new Intent("com.mobibob.promo.AboutActivity"));
                        stop();
                    }
                }
            };
            promoThread.start();
    
        }
    
        @Override
        public void onAnimationEnd(Animation animation) {
            Log.d(TAG, "onAnimationEnd");
            startActivity(new Intent("com.mobibob.promo.AboutActivity"));
        }
    }
    
    1 回复  |  直到 14 年前
        1
  •  2
  •   Rich Schuler    14 年前

    Animation#setAnimationListener 任何地方。你需要打电话 r.setAnimationListener(PromoActivity.this) q.setAnimationListener(PromoActivity.this) 以便调用侦听器。

    需要记住的是,您有两个动画,它们可能不会在同一时间完成。因此,您可能希望跟踪您的侦听器被调用的次数,以及只被调用的次数 startActivity 当达到应该结束的动画数时。