我想在我的Android应用中每2分钟重复播放一次动画,因为我的代码不起作用。请帮助我下面的代码。提前谢谢。
TableLayout = (TableLayout) this.findViewById(R.id.table01);
slide_down = AnimationUtils.loadAnimation(this, R.anim.slide_down);
slide_up = AnimationUtils.loadAnimation(this, R.anim.slide_up);
TableLayout.startAnimation(slide_down);
slide_down.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
TableLayout.startAnimation(slide_up);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
答案 0 :(得分:2)
TableLayout = (TableLayout) this.findViewById(R.id.table01);
slide_down = AnimationUtils.loadAnimation(this, R.anim.slide_down);
slide_up = AnimationUtils.loadAnimation(this, R.anim.slide_up);
TableLayout.startAnimation(slide_down);
slide_down.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
TableLayout.startAnimation(slide_up);
slide_up.setStartOffset(2000); // delay in ms
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
slide_up.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
TableLayout.startAnimation(slide_down);
slide_down.setStartOffset(2000); // delay in ms
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
我希望它能奏效!
答案 1 :(得分:1)
查看repeating animation with Timer
我同意接受的答案,即Handler
可与postDelayed
和Runnable
答案 2 :(得分:0)
请使用:
TimerTask slideDownTask= new TimerTask() {
public void run() {
TableLayout.startAnimation(slide_down);
});
}};
new Timer().schedule(slideDownTask, 0, 120000);