Exception
caused By:java.lang.RuntimeException:Unknown animation name:objectanimator
exception code
Fragmenttransaction ft = getfragmentmanager (). BeginTransaction (); // setcustomanimations () must be located before replace (), otherwise the effect is not up. Its two parameters are enter,exit effect respectively. The system currently offers two effects, namely Android. R.animator.fade_in and Android. R.animator.fade_outft.setcustomanimations (r.animator.slide_in_left,r.animator.slide_out_right); Ft.addtobackstack (null); Ft.replace (r.id.details,"detail"); Ft.commit ();
<?XML version= "1.0" encoding= "Utf-8"?> <Objectanimatorxmlns:android= "Http://schemas.android.com/apk/res/android"Android:interpolator= "@android: Interpolator/accelerate_decelerate"Android:valuefrom= " -1280"Android:valueto= "0"Android:valuetype= "Floattype"Android:propertyname= "X"android:duration= "$" />
<?XML version= "1.0" encoding= "Utf-8"?> <Objectanimatorxmlns:android= "Http://schemas.android.com/apk/res/android"Android:interpolator= "@android: Interpolator/accelerate_decelerate"Android:valuefrom= "0"Android:valueto= "The "Android:valuetype= "Floattype"Android:propertyname= "X"android:duration= "$" />
Animation Simple Description
The class that implements the custom animation is Objectanimator, not only for fragment, but also for view. In XML, the state of "from" and "to" are defined, and the interval is duration (milliseconds), and the rule of change is called Interpolator. The simplest interpolator is the linear, the @android:interpolator/linear, which is uniformly changed from the state from to the to state. The default interpolator is accelerate_decelerate. The system provides a way to view it in the source code/data/res/interpolator. Android:propertyname the dimension used for animation, in this case X for landscape, and the parameter in Setx () in root view is float, so the valuetype is set to Floattype. We can set our own dimensions. From is set to-1280, because this value for terminal equipment,-1280 pixel bits can ensure that the position is never visible to move in. If we do not set the From, the system will set the initial value according to the current value.
If we are going to set a change in two or more dimensions, we can use set tag, which corresponds to the Android Animatorset class, and the following example sets both the down and fade effects. Set has an attribute android:ordering, which defaults to together, that is, the changes of each dimension occur simultaneously, and can be set to sequentially in turn.
<?XML version= "1.0" encoding= "Utf-8"?> <Setxmlns:android= "Http://schemas.android.com/apk/res/android" > <ObjectanimatorAndroid:interpolator= "@android: Interpolator/accelerate_cubic"Android:valuefrom= "1"Android:valueto= "0"Android:valuetype= "Floattype"Android:propertyname= "Alpha"android:duration= "+"/> <ObjectanimatorAndroid:interpolator= "@android: Interpolator/accelerate_cubic"Android:valuefrom= "0"Android:valueto= "The "Android:valuetype= "Floattype"Android:propertyname= "Y"android:duration= "+"/> </Set>
Anomaly Analysis
The fragment in the V4 package is not fully supported for animations.
The Loadanimation method in the Fragmentmanager class
if(Transitionstyle = = 0) { return NULL; } //TypedArray attrs = mactivity.obtainstyledattributes (Transitionstyle,//com.android.internal.r.styleable.fragmentanimation); //int anim = Attrs.getresourceid (styleindex, 0); //attrs.recycle (); //if (Anim = = 0) {//return null; //} //return Animatorinflater.loadanimator (mactivity, anim); return NULL;
Animations that are processed inside the Animatorinflater.loadanimator:
String name =Parser.getname (); if(Name.equals ("Objectanimator") ) {Anim=Loadobjectanimator (c, attrs); } Else if(Name.equals ("animator") ) {Anim= Loadanimator (c, Attrs,NULL); } Else if(Name.equals ("Set") ) {Anim=NewAnimatorset (); TypedArray a=c.obtainstyledattributes (Attrs, Com.android.internal.r.styleable.animatorset); intordering =A.getint (com.android.internal.r.styleable.animatorset_ordering, TOGETHER); Createanimatorfromxml (c, Parser, Attrs, (Animatorset) anim, ordering); A.recycle (); } Else { Throw NewRuntimeException ("Unknown Animator Name:" +parser.getname ()); }
private static Objectanimator Loadobjectanimator (context context, AttributeSet attrs) t Hrows Notfoundexception {objectanimator Anim = new Objectanimator (); Loadanimator (context, attrs, anim); TypedArray a = Context.obtainstyledattributes (Attrs, Com.android.inter Nal. R.styleable.propertyanimator); String PropertyName = a.getstring ( Com.android.internal.r.styleable.propertyanimator_propertyname); Anim.setpropertyname (PropertyName); A.recycle (); return Anim; }
So
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.
I'm the dividing line of the king of the land Tiger.
Android--Fragment animation exception unknown animation name:objectanimator