-
Notifications
You must be signed in to change notification settings - Fork 12
Implement the Animation logic inside a native fragment subclass.
rutura edited this page Apr 16, 2017
·
1 revision
- Quick code :
@Override
public Animator onCreateAnimator(int transit, boolean enter,
int nextAnim) {
switch (transit) {
case FragmentTransaction.TRANSIT_FRAGMENT_FADE:
if (enter) {
return AnimatorInflater.loadAnimator(
getActivity(),
android.R.animator.fade_in);
} else {
return AnimatorInflater.loadAnimator(
getActivity(),
android.R.animator.fade_out);
}
case FragmentTransaction.TRANSIT_FRAGMENT_CLOSE:
if (enter) {
return AnimatorInflater.loadAnimator(
getActivity(),
R.animator.fragment_pop_enter);
} else {
return AnimatorInflater.loadAnimator(
getActivity(),
R.animator.fragment_pop_exit);
}
case FragmentTransaction.TRANSIT_FRAGMENT_OPEN:
default:
if (enter) {
return AnimatorInflater.loadAnimator(
getActivity(),
R.animator.fragment_enter);
} else {
return AnimatorInflater.loadAnimator(
getActivity(),
R.animator.fragment_exit);
}
}
}
- Just like the previous example , the animations are in /res/animator and wrapped in ObjectAnimator objects
- The animations are applied by loading them like this :
return AnimatorInflater.loadAnimator(
getActivity(),
R.animator.fragment_exit);