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"

}
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top