[Android] Activity transition animation

Android 5.0에서 activity나 fragment 전환할 때 Shared Element transition animation이 제공된다.

전환 전의 View에 transition name을 설정하고, 전환 후의 Activity나 fragment의 view에 transition name을 설정하면 animation이 동작된다.

 

적용하는 방법은 아래와 같다.


1. style.xml에서 windowSharedElementEnterTransition의 style을 적용하는 방법

<style name="BaseAppTheme" parent="android:Theme.Material">
  <!-- enable window content transitions -->
  <item name="android:windowContentTransitions">true</item>

  <!-- specify enter and exit transitions -->
  <item name="android:windowEnterTransition">@transition/explode</item>
  <item name="android:windowExitTransition">@transition/explode</item>

  <!-- specify shared element transitions -->
  <item name="android:windowSharedElementEnterTransition">
    @transition/change_image_transform</item>
  <item name="android:windowSharedElementExitTransition">
    @transition/change_image_transform</item>
</style>

change_image_transform.xml

<!-- res/transition/change_image_transform.xml -->
<!-- (see also Shared Transitions below) -->
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
  <changeImageTransform/>
</transitionSet>

2. activity에서 아래의 API를 사용하여 적용하는 방법

To specify transitions in your code, call these methods with a Transition object:

3. fragment에서 아래의 API를 사용하여 적용하는 방법

void setSharedElementEnterTransition(Transition transition)

Sets the Transition that will be used for shared elements transferred into the content Scene.
void setSharedElementReturnTransition(Transition transition)

Sets the Transition that will be used for shared elements transferred back during a pop of the back stack.

 

Continue reading “[Android] Activity transition animation”

[Android] Activity transition animation