PropertyValuesHolder crashes when used in XML animation

I am trying to use some propertyValuesHolder with objectAnimator in an animation that I defined in XML. When I load it, an exception from the runtime is thrown with the reason Unknown animator name: propertyValuesHolder

This is a complete animation taken directly from objectAnimator docs here :

 <?xml version="1.0" encoding="utf-8"?> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:repeatCount="1" android:repeatMode="reverse"> <propertyValuesHolder android:propertyName="x" android:valueTo="400"/> <propertyValuesHolder android:propertyName="y" android:valueTo="200"/> </objectAnimator> 

I use the following code to download and run the animation:

 Animator animator = AnimatorInflater.loadAnimator(getApplicationContext(), R.animator.example); animator.setTarget(view); animator.start(); 

I get the following from stacktrace:

 Caused by: java.lang.RuntimeException: Unknown animator name: propertyValuesHolder at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:592) at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:551) at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:122) at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:102) at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:87) 

This works when I use an animation that does not contain propertyValuesHolder . I cannot find examples on the Internet where this tag is used in XML. Am I doing something wrong or just not working?

+5
source share
1 answer

I believe the reason is that the XML element propertyValuesHolder is not supported until Lollipop.

If you look at AnimatorInflater , you will see that the first time the PropertyValuesHolder class is listed in 5.0.

+2
source

Source: https://habr.com/ru/post/1232701/


All Articles