Android动画意外停止

时间:2016-02-22 11:23:22

标签: android android-animation

我创建了以下动画:

public class MarginAnimation extends Animation {

    private final int fromX;
    private final int toX;
    private final View view;

    public MarginAnimation(final View view, final int fromX, final int toX) {
        this.fromX = fromX;
        this.toX = toX;
        this.view = view;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        MPLog.debug("Animation","interpolatedTime = "+interpolatedTime);
        setMargin(Math.round(fromX + (toX - fromX) * interpolatedTime));
    }

    private void setMargin(int margin){
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)view.getLayoutParams();
        params.rightMargin = margin;
        view.setLayoutParams(params);
    }

}

但在这里我发现我的动画有时会停止。这是日志:

02-22 13:14:44.138 25395-25395/com.test.test D/Animation: Start
02-22 13:14:44.148 25395-25395/com.test.test D/Animation: interpolatedTime = 0.0
02-22 13:14:44.148 25395-25395/com.test.test D/Animation: interpolatedTime = 0.0
02-22 13:14:44.163 25395-25395/com.test.test D/Animation: interpolatedTime = 0.017721295
02-22 13:14:44.183 25395-25395/com.test.test D/Animation: interpolatedTime = 0.0656842
02-22 13:14:44.198 25395-25395/com.test.test D/Animation: interpolatedTime = 0.14644662
02-22 13:14:44.218 25395-25395/com.test.test D/Animation: interpolatedTime = 0.2522707
02-22 13:14:44.233 25395-25395/com.test.test D/Animation: interpolatedTime = 0.36806342

此案例在0.36处停止,也未调用AnimationListener.onAnimationEnd()。有时它工作正常,达到1.0。为什么会这样?如何解决?

0 个答案:

没有答案
相关问题