The Fragment of Android programming causes the Unknown animation name: objectAnimator exception when an animation is used.

Source: Internet
Author: User

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.