Search code examples
androidandroid-animationobjectanimator

Method setX() with type int not found on target class class android.view.View


I am creating an animation for my Android app using android Property Animation. I create an XML file in res/animator/ directory.

<?xml version="1.0" encoding="utf-8"?>
<set android:ordering="sequentially" xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:propertyName="x"
        android:duration="500"
        android:valueFrom="0"
        android:valueTo="400"
        android:valueType="intType"/>
</set>

I inflate the XML resources in your code to an AnimatorSet object using AnimatorInflater.

AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(PropertyAnimationActivity.this,
            R.animator.animation_load_from_xml_example);
            set.setTarget(animatorSetView);
            set.start();

I get error

PropertyValuesHolder: Method setX() with type int not found on target class class android.view.View

Any idea how to fix the error.


Solution

  • You should change your valueType to android:valueType="floatType" as setX() takes an float value (ref).