medo medo - 5 months ago 17
Android Question

call method when animate View finished

i use this code for animate

x
and
y
position for
view


the code

v.animate().x(margin).y(0).setDuration(200).start();


how can i call method when this animation finished

i have this code also i can by it call method when finished the animate
but i cant set x and y for View

ValueAnimator varl = ValueAnimator.ofInt(from,to);
varl.setDuration(200);
varl.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {



@Override
public void onAnimationUpdate(ValueAnimator animation) {

}


});

varl.addListener(new AnimatorListenerAdapter()
{
@Override
public void onAnimationEnd(Animator animation)
{

// animate finish call method
}
});
varl.start();


i just thinking about make this code

v.animate().x(margin).y(0).setDuration(200).start();


inside the method onAnimationUpdate
i think its bad idea any another solution

Answer

Looks like the base class has a listener.

ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", 0.0f);
anim.addListener(new AnimatorListener() {
    ...
    @Override 
    public void onAnimationEnd(Animator animation) {
        // Do something.           
    }
    ...
});
anim.setDuration(300).start();
Comments