Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PropertyValuesHolder causes crash when used in XML defined animation

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?

like image 302
Harkin Avatar asked Oct 30 '22 18:10

Harkin


1 Answers

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.

like image 122
EvilDuck Avatar answered Nov 15 '22 04:11

EvilDuck