我需要停止一个运行翻译动画。Animation的.cancel()方法没有效果;不管怎样,动画会一直播放到最后。
如何取消正在运行的动画?
我需要停止一个运行翻译动画。Animation的.cancel()方法没有效果;不管怎样,动画会一直播放到最后。
如何取消正在运行的动画?
当前回答
如果你正在使用动画监听器,设置v.setAnimationListener(null)。对所有选项使用下面的代码。
v.getAnimation().cancel();
v.clearAnimation();
animation.setAnimationListener(null);
其他回答
首先,移除所有与animatior或animator set相关的监听器。然后取消动画器或动画器集。
inwardAnimationSet.removeAllListeners()
inwardAnimationSet.cancel()
你必须使用.clearAnimation();方法:
runOnUiThread(new Runnable() {
@Override
public void run() {
v.clearAnimation();
}
});
用这种方式:
// start animation
TranslateAnimation anim = new TranslateAnimation( 0, 100 , 0, 100);
anim.setDuration(1000);
anim.setFillAfter( true );
view.startAnimation(anim);
// end animation or cancel that
view.getAnimation().cancel();
view.clearAnimation();
取消()
取消动画。取消一个动画会调用该动画 监听器,如果设置,通知动画的结束。 如果手动取消动画,则必须调用reset() 在再次开始动画之前。
clearAnimation ()
取消此视图的任何动画。
你可以尝试做的是在停止动画之前从动画中获取变换矩阵,并检查矩阵内容以获得你正在寻找的位置值。
下面是您应该研究的api
gettransform (long currentTime, transform outTransformation)
getMatrix ()
getValues (float[] values)
例如(一些伪代码。我还没有测试这个):
Transformation outTransformation = new Transformation();
myAnimation.getTransformation(currentTime, outTransformation);
Matrix transformationMatrix = outTransformation.getMatrix();
float[] matrixValues = new float[9];
transformationMatrix.getValues(matrixValues);
float transX = matrixValues[Matrix.MTRANS_X];
float transY = matrixValues[Matrix.MTRANS_Y];
Use the method setAnimation(null) to stop an animation, it exposed as public method in View.java, it is the base class for all widgets, which are used to create interactive UI components (buttons, text fields, etc.). /** * 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)