Thursday, February 9, 2017

Animations for the app

I would like to have general animations (transitions) between my activities. There are many possibilities. Use TransitionManager, use Activity#overridePendingTransition(), use ActivityOptions, FragmentTransaction#setCusotmAnimation()...

One general solution would be:

<style name="ActivityAnimations" parent="@android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">@anim/slide_up_in</item>
<item name="android:activityOpenExitAnimation">@null</item>
<item name="android:activityCloseEnterAnimation">@null</item>
<item name="android:activityCloseExitAnimation">@anim/slide_out_right</item>
</style>


and apply in the base theme:
<item name="android:windowAnimationStyle">@style/ActivityAnimations</item>


To understand what those means, here is an excerpt from here
intactivityCloseEnterAnimationWhen closing the current activity, this is the animation
 that is run on the next activity (which is entering the screen).
intactivityCloseExitAnimationWhen closing the current activity,
this is the animation that is run on the current activity (which is exiting the screen).
intactivityOpenEnterAnimationWhen opening a new activity,
this is the animation that is run on the next activity (which is entering the screen).
intactivityOpenExitAnimationWhen opening a new activity,
this is the animation that is run on the previous activity (which is exiting the screen).


<!-- In case we need to generalize for the fragments
<item name="fragmentOpenEnterAnimation">@animator/fragment_open_enter</item>
<item name="fragmentOpenExitAnimation">@animator/fragment_open_exit</item>
<item name="fragmentCloseEnterAnimation">@animator/fragment_close_enter</item>
<item name="fragmentCloseExitAnimation">@animator/fragment_close_exit</item>-->

No comments: