android:使用时间表调用动画时出现问题
当我的应用程序加载时,我让它对屏幕进行动画处理。在 onAnimationEnd 中,我调用 Schedule 让它在 2 秒后调用一个函数,该函数将调用一个动画来再次将视图动画化。目前它已开始动画化,但调度程序似乎从未调用过该动画。如果我单击主页,然后返回应用程序,它会立即调用动画。如果计划正常运行,为什么应用程序会等到失去焦点然后重新获得焦点才能实际触发计划应该调用的函数。代码如下:
这些是在 onCreate 中定义的:
slideTopIn = AnimationUtils.loadAnimation(this, R.anim.slide_top_in);
slideTopIn.setAnimationListener(slideTopInListener);
slideTopOut = AnimationUtils.loadAnimation(this, R.anim.slide_top_out);
slideTopOut.setAnimationListener(slideTopOutListener);
freeAlertMsg.startAnimation(slideTopIn);
这些是在 Activity 类的 onCreate 之外定义的:
private AnimationListener slideTopInListener = new AnimationListener(){
public void onAnimationEnd(Animation anim){
alertTimer.schedule(new Runnable() {
public void run() { hideFreeAlert(); }
}, 2, TimeUnit.SECONDS);
};
public void onAnimationStart(Animation anim){
freeAlertMsg.setVisibility(View.VISIBLE);
};
public void onAnimationRepeat(Animation anim){
};
};
private AnimationListener slideTopOutListener = new AnimationListener(){
public void onAnimationEnd(Animation anim){
mainScreen.removeView(freeAlert);
};
public void onAnimationStart(Animation anim){
Log.d("Animation Listener","slideTopOutListener");
};
public void onAnimationRepeat(Animation anim){
};
};
private void hideFreeAlert(){
freeAlertMsg.startAnimation(slideTopOut);
}
所以基本上它执行 startAnimation(slideTopIn)。然后什么也没有发生。如果我单击主页,然后返回应用程序,则 startAnimation(slideTopOut) 立即执行。我猜计划实际上会运行,但由于某种原因从未触发动画。
When my app loads I have it animate a screen in. In the onAnimationEnd I call schedule to have it call a function 2 seconds later that will call an animation to animate the view out again. Currently it animates in, but the scheduler never seems to call the animate out. If I click home, then go back to the app it immediately calls the animate out. Why would, if the schedule is working, the app wait until it loses focus then gets focus back to actually trigger the function the schedule is supposed to call. Here's the code:
These are defined in the onCreate:
slideTopIn = AnimationUtils.loadAnimation(this, R.anim.slide_top_in);
slideTopIn.setAnimationListener(slideTopInListener);
slideTopOut = AnimationUtils.loadAnimation(this, R.anim.slide_top_out);
slideTopOut.setAnimationListener(slideTopOutListener);
freeAlertMsg.startAnimation(slideTopIn);
These are defined outside the onCreate within the activity class:
private AnimationListener slideTopInListener = new AnimationListener(){
public void onAnimationEnd(Animation anim){
alertTimer.schedule(new Runnable() {
public void run() { hideFreeAlert(); }
}, 2, TimeUnit.SECONDS);
};
public void onAnimationStart(Animation anim){
freeAlertMsg.setVisibility(View.VISIBLE);
};
public void onAnimationRepeat(Animation anim){
};
};
private AnimationListener slideTopOutListener = new AnimationListener(){
public void onAnimationEnd(Animation anim){
mainScreen.removeView(freeAlert);
};
public void onAnimationStart(Animation anim){
Log.d("Animation Listener","slideTopOutListener");
};
public void onAnimationRepeat(Animation anim){
};
};
private void hideFreeAlert(){
freeAlertMsg.startAnimation(slideTopOut);
}
So basically it executes the startAnimation(slideTopIn). Then nothing happens. If i click home, then go back to the app, the startAnimation(slideTopOut) immediately executes. I'm guessing the schedule actually runs but never triggers the animation for some reason.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在任何
View
上调用postDelayed()
即可。Just call
postDelayed()
on anyView
.