我的动画有效,当线程结束时,下一个屏幕的意图会触发,但不会从动画结束时触发。我为所有AnimationListener's
回调添加了日志条目(只有End在此列表中),但没有记录。
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"));
}
}
答案 0 :(得分:2)
你不是在任何地方打电话给Animation#setAnimationListener
。您需要调用r.setAnimationListener(PromoActivity.this)
和/或q.setAnimationListener(PromoActivity.this)
来调用侦听器。
要记住的是,您有两个动画,但它们可能无法完全同时完成。因此,您可能希望跟踪您的监听器被调用的次数,并且只在达到应该结束的动画数量时调用startActivity
。