我有一个图像从location1到location2的翻译动画。然而,在动画期间的任何时候,如果用户单击一个按钮,那么我想应用另一个转换动画从图像的位置到location3(即使动画还没有完成)。有什么办法吗?
感谢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"
}
为什么不使用ObjectAnimators?
你可以为一个特定的目标创建一个动画器(或者通过animate()获得一个视图,如果你运行在一个版本大于等于API级别12),然后翻译,调整大小,淡出,…你的对象。
如果由于某些特殊原因第一个动画被取消,你可以调用cancel,然后视图将保持当前状态。然后,如果你基于当前值创建另一个动画器,你应该能够轻松地执行另一个动画。