블로그 이미지
흰색앵초

calendar

1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

Notice

2014. 10. 21. 14:13 프로그래밍/Android


ImageView에 Flip 애니메이션을 주고 싶으면 아래와 같이 하시면 됩니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
 
public class MainActivity extends Activity {
 
    ImageView iv1;
    Button btn1;
     
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         
        btn1 = (Button) findViewById(R.id.button1);
        iv1 = (ImageView) findViewById(R.id.imageView1);
         
        btn1.setOnClickListener(new OnClickListener() {
             
            @Override
            public void onClick(View v) {
                ObjectAnimator animator = ObjectAnimator.ofFloat(iv1, "rotationY", 0, 720);
                animator.setDuration(2000); 
                animator.start();
            }
        });
         
    }
}

ObjectAnimator animator = ObjectAnimator.ofFloat(iv1, "rotationY", 0, 720);
이부분이 중요한데 순서대로 

iv1 << 애니메이션을 줄 이미지뷰를 넣으시고
"rotationX" << 줄효과 rotationY를 하면 Y축으로 rotationX를 하면 X축으로 회전하게 됩니다.
0 << 시작할 각도
720 << 애니메이션이 종료될 시점의 각도

를 넣으셔서 처리하시면 됩니다.

회전축을 정하고 싶으시면 imageView에 .setPivotX .setPivotY로 미리 지정해두면됩니다.

posted by 흰색앵초