I'm trying to use some propertyValuesHolder
with an objectAnimator
in an animation I've defined in XML. When I load it a runtime exception is thrown with the reason Unknown animator name: propertyValuesHolder
This is the full animation taken directly from the 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'm using the following code to load and start the animation:
Animator animator = AnimatorInflater.loadAnimator(getApplicationContext(), R.animator.example);
animator.setTarget(view);
animator.start();
The cause I get from the stacktrace is this:
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 doesn't contain a propertyValuesHolder
. I can't find any examples online where that tag is used in XML. Am I doing something wrong or does it just not work?
I believe the reason is that propertyValuesHolder XML element is not supported before Lollipop.
If you take a look at AnimatorInflater you will see that first time PropertyValuesHolder class is referenced there is in 5.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With