动画完成后删除视图

时间:2015-12-04 11:40:07

标签: java android animation

我正在寻找一种从带有缩放动画的布局中删除视图的方法。方法removeFromLayout应该将它们缩放到0,并且在每个View完成动画后,应该清除叠层。

public void removeFromLayout(){
        for(int i=all.size()-1;i>=0;i--){
            all.get(i).animate()
                    .scaleX(0)
                    .scaleY(0)
                    .setDuration(200)
                    .setStartDelay(i*MainActivity.FIELDSIZE).start();
        }
        //After all animations are done, they should be removed
        layout.removeAllViews();
    }

所以我的问题是,如何“延迟”layout.removeAllViews()?

提前致谢

2 个答案:

答案 0 :(得分:2)

考虑使用ObjectAnimator类。您可以设置动画侦听器。以下代码段将为您提供一个想法。

ObjectAnimator scaleDown = ObjectAnimator.ofPropertyValuesHolder(view, 
    PropertyValuesHolder.ofFloat("scaleX", 0.5f),
    PropertyValuesHolder.ofFloat("scaleY", 0.5f));
scaleDown.setDuration(1000);
scaleDown.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
               //Animation is complete, you can remove all your views here
               layout.removeAllViews();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
scaleDown.start();

答案 1 :(得分:0)

创建一个CountDownTimer:

new CountDownTimer(200, 10) {

 public void onTick(long millisUntilFinished) 
 {}

 public void onFinish() {
     layout.removeAllViews();
 }
 }.start();