Question

I have a translate animation of an image from location1 to location2. However at any time during the animation, if a user click a button then I want to apply another translate animation from where the image at to location3 (even if the animation has not finished). Any way I can do that?

Thanks

TranslateAnimation translate = new TranslateAnimation(0, mDestLoc[0]-mSrcLoc[0], 0, mDestLoc[1]-mSrcLoc[1]);            
        translate.setFillAfter(true);
        translate.setDuration(getDuration());
        ball.startAnimation(translate);




void onbuttonClicked(){
// stop previous animation and translate image to location 3 "From where it stopped"

}
Was it helpful?

Solution

why don't you use ObjectAnimators?

You can create an animator for a particular target(or obtain the view one through animate() if you're running on a version greater-equal API level 12) and then translate, resize, fade,... your object.

If for some particular reasons the first animation is cancelled, you can call cancel and then the view will persist the current status. Then, if you create another animator based on the current values you should be able to easily perform another animation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top