After the Fragment is switched, an exception occurs:
Caused by: java. lang. RuntimeException: Unknown animation name: objectAnimator
As follows:
My code is as follows:
fragment = Fragment.instantiate(getActivity(), clz.getName()); fragment.setArguments(args); ft.setCustomAnimations(R.animator.fragment_rotate_enter, R.animator.fragment_rotate_exit, R.animator.fragment_rotate_pop_enter, R.animator.fragment_rotate_pop_exit); ft.replace(R.id.fragment_stub, fragment); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.addToBackStack(null);
My animation file is as follows, and the other three are similar, so I will not post them:
There are many sayings on the Internet about this exception, but I have read the explanation and I have not tried to fix it. Here, I will explain the reason:
First, I used the objectAnimator animation label,
The second reason is that Fragment is in V4.
The reason is that Fragment in V4 does not fully support animation. If you have V4 source code, you can refer to the loadAnimation method in the FragmentManager class. I will map it directly here:
The location at the mark is the key code. The objectAnimator-related labels are processed here, as shown in:
Therefore, it will cause the exception on the title.
Here I will extend some content: Which animation labels does Fragment in V4 support? Let's take a look at the source code in the V4 package:
Fragment in the source code, which does not comment out the animation to load the code.
Summary:
When Fragment is used in a V4 package, the animation effect is switched. The animation file cannot contain tags such as objectAnimator and Animator. If you need to use this function, replace the Fragment class in the V4 package used in the project with the Fragment class in the source code.Related Classes.
Finally, attach the animation effect I want to do: the switching effect of a flop is based on the Code modified by APIDemo:
Http://download.csdn.net/detail/xyz_fly/7576099