상세 컨텐츠

본문 제목

[TIP]애니메이션 구현

프로그램개발/안드로이드

by fsteam 2011. 10. 4. 15:23

본문

동적인 화면을 구성하고자 할 경우.. 
onDraw 등을 써서 직접 화면을 그릴수도 있겠지만.. 안드로이드에서는 간단하게 애니메이션을 구현할 수 있다.

1. XML을 이용하는 방법
1) /res/anim 폴더에 아래와 같은 xml 파일을 만든다.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate android:fromDegrees="0" android:toDegrees="30" android:pivotX="5%" android:pivotY="85%" android:duration="300" />
</set>
2) 소스에서 animation 적용하기
Animation anim1 = AnimationUtils.loadAnimation(this, R.anim.xxx);
ImageView star1 = (ImageView)findViewById(R.id.imgStar1);
star1.startAnimation(anim1);

위의 예제는 star1 이라는 이미지가 시계방향으로 30도 회전하는 효과를 보여준다.
(x, y 좌표는 5%, 85% 부분이 중심축이 되어 회전한다. )

2. 소스에서 구현하는 방법
 도 있으나.. 걍 xml 로 구현하는게 편하지 않나..? ㅎㅎ 

관련글 더보기