1

我有一个使用以下代码旋转的位图。问题是设置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);
}
4

0 回答 0