상세 컨텐츠

본문 제목

[안드로이드] 두번쨰 Activity 간 애니메이션 효과 적용하는법

Android.. Story

by HeyLee 2011. 3. 23. 18:14

본문


화면 전환간에 애니메이션 효과를 적용하는 포스트 입니다.

역시나 매우 간단..아주아주 간단한 예제 포함입니다. (예전 예제에 추가 내용)

전에 만들엇던 예제에서 추가해보겠습니다.

화면 간 애니메이션 효과를 넣는 함수 역시 제공 되고있습니다.

public void overridePendingTransition (int enterAnim, int exitAnim)
Since: API Level 5

Call immediately after one of the flavors of startActivity(Intent) or finish() to specify an explicit transition animation to perform next.

Parameters
enterAnim A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.
exitAnim A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation. 


직접 써보겠습니다.

overridePendingTransition(R.anim.fade, R.anim.hold);

res/anim 폴더 안에 fade.xml 와 hold.xml를 적용시킨것입니다.
(기본적으로 anim폴더는 없으므로 만들어주셔야합니다.(다른이름도 무방하지만 가독성을 위해서..))

애니메이션은 안드로이드에서 기본제공 하는것입니다.
화면이 위에서 아래로 움직이는것이나 오른쪽에서 왼쪽 기타 여러다른 애니메이션이 필요하시면 
직접 xml를 제작해서 쓰셔도 무방합니다.

fade.xml  (화면이 서서히 사라지는 효과)

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


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

       android:interpolator="@android:anim/accelerate_interpolator"

       android:fromAlpha="0.0" android:toAlpha="1.0"

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



hold.xml (기본 자리 고정 효과)

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


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

       android:interpolator="@android:anim/accelerate_interpolator"

       android:fromXDelta="0" android:toXDelta="0"

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



요런식으로 적용시켜서 쓰시면 되겠습니다.


관련글 더보기

댓글 영역