별 건 아니고요...우선 동영상부터..^^;



단순히 회전을 한것에서 그친게 아니라 회전시 뷰의 크기가 적절하게 줄어들도록 하였습니다.

 

 

 package com.nobrain.rotateanim.test;

import android.util.Log;
import android.view.animation.RotateAnimation;
import android.view.animation.Transformation;

public class TiffRotationAnimation extends RotateAnimation {

    private float fromDegree;
    private float toDegree;
    private int pivotX;
    private int pivotY;
    private float viewMulti;

    TiffRotationAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType,
            float pivotYValue) {
        super(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue);

        this.fromDegree = fromDegrees;
        this.toDegree = toDegrees;
        
        setFillEnabled(true);
        setFillAfter(true);
        setDuration(500);
    }


    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        super.applyTransformation(interpolatedTime, t);
        
        float degrees = fromDegree + ((toDegree - fromDegree) * interpolatedTime);
        
        t.getMatrix().setRotate(degrees, pivotX, pivotY);

            
        int temp = (int) Math.abs(fromDegree / 90);

        float scale = 0f;
        if(temp % 2 == 0){
         
         scale = 1.0f + (viewMulti - 1.0f) * interpolatedTime;
        }else{
         scale = viewMulti + (1.0f - viewMulti) * interpolatedTime;
        }
        Log.d("INFO", "Scale : "+scale + "");
        Log.d("INFO", "viewMulti : "+viewMulti);
        t.getMatrix().preScale(scale, scale, pivotX, pivotY);

    }

    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
        
        this.pivotX = width / 2;
        this.pivotY = height / 2;
        
        this.viewMulti = ((float) width) / ((float) height);
        
    }


}

 

위의 소스는 애니메이션 클래스를 직접 상속받아 일부를 오버라이드 한 것입니다.

 

키 포인트는 applyTransformation 메쏘드로

애니메이션 동작동안 뷰의 크기를 컨트롤해주는 영역입니다.

 

수학적 계산은..어쩌다가 얻어맞은거니 태클거시지 마시길 -ㅅ-);

 

해당 애니메이션 호출 방법은

 

아래와 같습니다.

 

  new TiffRotationAnimation(fromD, toD, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);

 

fromD 는 시작하는 각도

toD 는 종료하는 각도

 

위의 영상은 0 -> 90, 90 ->180, 0 -> -90, -90 -> -180

이런식으로 동작하도록 되어있습니다.

 

회전 동작을 너무 밋밋하게 쓰시지마시고 가급적이면 위와 같이 애니메이션을 곁들여보시기 바랍니다.

 

덧1. setFillBefore 메쏘드 사용으로 인해 터치 포인트도 회전됩니다. 터치 액션이 필요하신 분들이라면 반드시 해당 뷰에도 터치 액션을 별도로 정의해주셔야 합니다.

 

덧2. 버그따윈 많습니다..그냥 싸질러보는거죠 ~_~