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);
使用方法 setAnimation(null) 来停止动画,它在 View.java 中作为公共方法公开,它是所有 widgets 的基类,用于创建交互式UI组件(按钮,文本字段等) . /** * Sets the next animation to play for this view. * If you want the animation to play immediately, use * {@link #startAnimation(android.view.animation.Animation)} instead. * This method provides allows fine-grained * control over the start time and invalidation, but you * must make sure that 1) the animation has a start time set, and * 2) the view's parent (which controls animations on its children) * will be invalidated when the animation is supposed to * start. * * @param animation The next animation, or null. */ public void setAnimation(Animation animation)
7 回答
在你叫
startAnimation()
的View
上调用clearAnimation()
.在Android 4.4.4上,似乎我可以在View上停止alpha淡入淡出动画的唯一方法是调用
View.animate().cancel()
(即在View的ViewPropertyAnimator上调用.cancel()
) .这是我在ICS之前和之后用于兼容性的代码:
...用方法:
这是我要停止的动画:
如果您正在使用动画侦听器,请设置
v.setAnimationListener(null)
. 对所有选项使用以下代码 .你必须使用.clearAnimation(); UI线程中的方法:
您可以尝试做的是在停止之前从动画中获取变换矩阵并检查Matrix内容以获取您要查找的位置值 .
以下是你应该研究的api
public boolean getTransformation (long currentTime, Transformation outTransformation)
public Matrix getMatrix ()
public void getValues (float[] values)
所以例如(一些伪代码 . 我没有测试过这个):
使用方法 setAnimation(null) 来停止动画,它在 View.java 中作为公共方法公开,它是所有 widgets 的基类,用于创建交互式UI组件(按钮,文本字段等) .
/** * Sets the next animation to play for this view. * If you want the animation to play immediately, use * {@link #startAnimation(android.view.animation.Animation)} instead. * This method provides allows fine-grained * control over the start time and invalidation, but you * must make sure that 1) the animation has a start time set, and * 2) the view's parent (which controls animations on its children) * will be invalidated when the animation is supposed to * start. * * @param animation The next animation, or null. */ public void setAnimation(Animation animation)
要停止动画,您可以设置不执行任何操作的objectAnimator,例如
首先当手动翻转时,动画从左到右:
然后当切换到自动翻转时,没有动画