Skip to content

Transition animations

JingYeoh edited this page Dec 18, 2017 · 1 revision

Fragment default has not transition animation when we are using fragment.But sometimes we need use transition for fragment,the android native fragment provide api to support,but it's not easy to use,so this library can make you easier for fragment transition animation.

Support:

  • Push fragment onto the stack
  • Remove fragment from the stack
  • Show fragment
  • Replace fragment
  • Hide fragment
  • Remove fragment
  • custom Animation class

This library only support Xml animations,if you need more complicated animation,you can extend Animation class and override Fragment native method,you can see the demo class ContainerFragment.java,there are two ways to use fragment transition animations.

How to use

Add @Animator animation in your fragment needs transition animations.This animations has four params: enter/exit/popEnter/popExit correspond respectively with entering animation/exiting animation/pop fragment the this stack entering animation/pop in the stack exiting animation.

Custom Xml animation

@Animator(enter = R.anim.push_left_in_no_alpha, exit = R.anim.push_right_out_no_alpha,
    popEnter = R.anim.push_right_in_no_alpha, popExit = R.anim.push_left_out_no_alpha)
@Puppet
public class StartFragment extend Fragment

Custom animation extends Animation class

@Puppet
public class StartFragment extend Fragment{
  @Override
  public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
    if (customAnim) return super.onCreateAnimation(transit, enter, nextAnim);
    if (enter) {
      return AnimationHelper.createRotate3dEnterAnimation();
    } else {
      return AnimationHelper.createRotate3dExitAnimation();
    }
  }
}