Java/Android

간단한 애니메이션

체리필터 2013. 8. 8. 09:22
728x90
반응형

View 화면이 상, 하, 좌, 우에서 날라 들어오거나 다시 들어가는 간단한 애니메이션이 필요해서 검색 중 http://developer.android.com/guide/topics/graphics/view-animation.html 를 발견하게 되었다.

이를 응용해서 현재 개발중인 프로젝트에 사용하였다.


관련 소스는 아래와 같다.

자세한 소스 분석은 언제나 그렇듯이 알아서 ^^


res/anim 아래 animation xml 파일을 만든다. 아래와 같이 from x가 100%에서 시작하면 오른쪽에 숨어 있다가 to x인 0의 위치, 즉 원래 화면 안으로 들어오는 부분이다. 따라서 이름도 slide_in_from_right.xml로 만들었다.

이처럼 100%, -100% 그리고 X, Y만 바꿔가면 상, 하, 좌, 우 애니메이션을 만들 수 있다.


<?xml version="1.0" encoding="utf-8"?>

<translate xmlns:android="http://schemas.android.com/apk/res/android"

    android:duration="@android:integer/config_longAnimTime"

    android:fromXDelta="100%p"

    android:toXDelta="0" />


그리고 나서 위 링크에서 볼 수 있는 것처럼 아래와 같이 사용하면 된다.


Animation inFromRightAni = AnimationUtils.loadAnimation(this, R.anim.slide_in_from_right);

view.startAnimation(inFromRightAni);



728x90
반응형