我需要停止正在运行的翻译动画。Animation的.cancel()方法没有任何效果;动画无论如何都会一直播放到最后。
如何取消正在运行的动画?
发布于 2010-11-06 17:47:09
在您调用startAnimation()的任何View上调用clearAnimation()。
发布于 2014-09-30 02:27:05
在安卓4.4.4上,似乎唯一可以停止视图上的alpha淡出动画的方法是调用View.animate().cancel() (即,在视图的ViewPropertyAnimator上调用.cancel() )。
下面是我用来在ICS前后兼容的代码:
public void stopAnimation(View v) {
v.clearAnimation();
if (canCancelAnimation()) {
v.animate().cancel();
}
}..。使用该方法:
/**
* Returns true if the API level supports canceling existing animations via the
* ViewPropertyAnimator, and false if it does not
* @return true if the API level supports canceling existing animations via the
* ViewPropertyAnimator, and false if it does not
*/
public static boolean canCancelAnimation() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
}下面是我要停止的动画:
v.setAlpha(0f);
v.setVisibility(View.VISIBLE);
// Animate the content view to 100% opacity, and clear any animation listener set on the view.
v.animate()
.alpha(1f)
.setDuration(animationDuration)
.setListener(null);发布于 2015-05-28 16:59:08
如果使用的是动画侦听器,请设置v.setAnimationListener(null)。将以下代码与所有选项一起使用。
v.getAnimation().cancel();
v.clearAnimation();
animation.setAnimationListener(null);https://stackoverflow.com/questions/4112599
复制相似问题