在Android应用中每隔几分钟重复开始动画

时间:2016-06-03 02:50:36

标签: java android xml

我想在我的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) {


        }
    });

3 个答案:

答案 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可与postDelayedRunnable

一起使用

答案 2 :(得分:0)

请使用:

   TimerTask slideDownTask= new TimerTask() {
        public void run() {
              TableLayout.startAnimation(slide_down);
        });
    }};
    new Timer().schedule(slideDownTask, 0, 120000);