Android programming fragment using animations to cause unknown animation name:objectanimator exceptions

Source: Internet
Author: User

When switching animations for fragment, an exception was encountered after startup:

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, the other three is similar, do not post it out:

<set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <objectanimator        android: duration= "        android:propertyname=" RotationY "        android:valuefrom=" 180.0 "        android:valueto=" 360.0 "        android:valuetype= "Floattype"/>    <objectanimator        android:duration= "$"        android: Propertyname= "Alpha"        android:valuefrom= "0.0"        android:valueto= "1.0"        android:valuetype= "Floattype" /></set>

For this anomaly, there are many statements on the Internet, but I have read the explanation, there is no point. Here, let me give you a specific explanation:

The first is because I used the animated label Objectanimator,

The second is because fragment I use in the V4 package.


The reason is here: the fragment in the V4 package is not fully supported for animations. If the hand has V4 source code of the classmate, can be turned out to see specifically-in the Fragmentmanager class Loadanimation method. I have a direct map here:


The location at the marker is the key code. The label associated with the Objectanimator is processed in this case, as shown in:


That's why the exception in the header is created.


I'm going to extend some of the content here: What animated tags does the fragment in the V4 package support? Look at the source code in the V4 package:

The error is abnormal, which is reported here.


So, isn't it possible to switch between Objectanimator's animated labels for fragment?

Of course, it is not impossible, if you want to use this animation, please use the source code in the fragment, it is not commented out that the animation loaded the tag.


Summary:
When you use the fragment in the V4 package, the animated file cannot contain Objectanimator,animator tags, which are used for the toggle animation effect. If you must use it, replace the V4 package in the project with the fragment related classes in the source code fragment
related classes.


Finally, attach the animation effect I want to do: a flop switch effect, which is based on Apidemo modified code:

http://download.csdn.net/detail/xyz_fly/7576099


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.