Reputation: 271
im looking for a way to remove Views from a layout with a scale animation. The method removeFromLayout should scale them to 0 and after every View is done with the animation, the layoud should be cleared.
public void removeFromLayout(){
for(int i=all.size()-1;i>=0;i--){
all.get(i).animate()
.scaleX(0)
.scaleY(0)
.setDuration(200)
.setStartDelay(i*Activity.SIZE).start();
}
//After all animations are done, they should be removed
layout.removeAllViews();
}
So my question is, how can I "delay" layout.removeAllViews()?
Thanks in advance
Upvotes: 0
Views: 117
Reputation: 5941
Consider using ObjectAnimator class. You can set the animation listener. The following code snippet will give you an idea.
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();
Upvotes: 2
Reputation: 4134
Create a CountDownTimer:
new CountDownTimer(200, 10) {
public void onTick(long millisUntilFinished)
{}
public void onFinish() {
layout.removeAllViews();
}
}.start();
Upvotes: 0