gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 22:33:00 35 4
gpt4 key购买 nike

我的动画有效,当线程结束时,将触发下一个屏幕的 Intent ,但它不会从动画结束时触发。我为所有 AnimationListener 的 回调添加了日志条目(只有 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"));
}
}

最佳答案

您不会在任何地方调用 Animation#setAnimationListener。您需要调用 r.setAnimationListener(PromoActivity.this) 和/或 q.setAnimationListener(PromoActivity.this) 才能调用监听器。

请记住,您有两个动画,它们可能不会同时完成。因此,您可能想要跟踪您的监听器被调用了多少次,并且仅在达到应该结束的动画次数时才调用 startActivity

关于android - 为什么我的 Android 动画不调用我的 onAnimationEnd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3172988/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com