Android旋转位图。 setDuration不会改变速度

时间:2013-01-31 16:35:52

标签: android animation rotation

我有一个位图,我用以下代码旋转。问题是设置rotate.setDuration。我尝试将值更改为900000,但是当我的ACTION_UP位图始终以相同的速度旋转到起始位置时。

        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            mCircle.clearAnimation();
            angleDegree = Math.toDegrees(Math.atan2(x - xc, yc - y));
            if (angleDegree>0){angleDegree=angleDegree-360;}
            angleDifference =angleDegree;      
            mCurrAngle =angleDegree-angleDifference;
            mPrevAngle = mCurrAngle;
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            angleDegree = Math.toDegrees(Math.atan2(x - xc, yc - y));
            if (angleDegree>0){angleDegree=angleDegree-360;}
            mCurrAngle =angleDegree-angleDifference;
            mPrevAngle = mCurrAngle;
            animate(mPrevAngle, mCurrAngle, 0);
            break;
        }
        case MotionEvent.ACTION_UP : {
            timeback = 9000000;
            mPrevAngle = mCurrAngle = 0;
            animate(mPrevAngle, mCurrAngle, timeback);
            break;
        }
        }

    private void animate(double fromDegrees, double toDegrees, long setDuration) {
        final RotateAnimation rotate = new RotateAnimation((float) fromDegrees, (float) toDegrees,
                RotateAnimation.RELATIVE_TO_SELF, 0.5f,
                RotateAnimation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(setDuration);
        rotate.setFillEnabled(true);
        rotate.setFillAfter(true);
        mCircle.startAnimation(rotate);
}

0 个答案:

没有答案