SHARE
TWEET

Untitled

a guest Feb 17th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void performTransition()
  2.     {
  3.         if (isDestroyed())
  4.         {
  5.             return;
  6.         }
  7.         Fragment previousFragment = mFragmentManager.findFragmentById(R.id.fragment_container);
  8.         Fragment nextFragment = Fragment2.newInstance();
  9.  
  10.         FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
  11.  
  12.         // 1. Exit for Previous Fragment
  13.         Fade exitFade = new Fade();
  14.         exitFade.setDuration(FADE_DEFAULT_TIME);
  15.         previousFragment.setExitTransition(exitFade);
  16.  
  17.         // 2. Shared Elements Transition
  18.         TransitionSet enterTransitionSet = new TransitionSet();
  19.         enterTransitionSet.addTransition(TransitionInflater.from(this).inflateTransition(android.R.transition.move));
  20.         enterTransitionSet.setDuration(MOVE_DEFAULT_TIME);
  21.         enterTransitionSet.setStartDelay(FADE_DEFAULT_TIME);
  22.         nextFragment.setSharedElementEnterTransition(enterTransitionSet);
  23.  
  24.         // 3. Enter Transition for New Fragment
  25.         Fade enterFade = new Fade();
  26.         enterFade.setStartDelay(MOVE_DEFAULT_TIME + FADE_DEFAULT_TIME);
  27.         enterFade.setDuration(FADE_DEFAULT_TIME);
  28.         nextFragment.setEnterTransition(enterFade);
  29.  
  30.         View logo = ButterKnife.findById(this, R.id.fragment1_logo);
  31.         fragmentTransaction.addSharedElement(logo, logo.getTransitionName());
  32.         fragmentTransaction.replace(R.id.fragment_container, nextFragment);
  33.         fragmentTransaction.commitAllowingStateLoss();
  34.     }
RAW Paste Data
Top