How to stop an animation (cancel() does not work)

后端 未结 7 1071
轮回少年
轮回少年 2020-11-29 16:52

I need to stop a running translate animation. The .cancel() method of Animation has no effect; the animation goes until the end anyway.

How

7条回答
  •  星月不相逢
    2020-11-29 17:22

    What you can try to do is get the transformation Matrix from the animation before you stop it and inspect the Matrix contents to get the position values you are looking for.

    Here are the api's you should look into

    public boolean getTransformation (long currentTime, Transformation outTransformation)

    public Matrix getMatrix ()

    public void getValues (float[] values)

    So for example (some pseudo code. I have not tested this):

    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];
    

提交回复
热议问题