tags:

views:

57

answers:

1

I have an animation specified in xml like this:

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"&gt;
·       <translate android:fromXDelta="0" android:toXDelta="100%p" android:duration="300" android:interpolator="@android:anim/anticipate_overshoot_interpolator" />
·       <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />
</set>

This file is res/anim/push_right_in.xml

Then in Java code I try to load it like this:

mAnimationRightIn = AnimationUtils.loadAnimation(this, R.anim.push_right_in);

It works perfectly fine on 1.6, 2.1, 2.2, but throws an exception on 1.5:

clock.ClockSelectActivity}: java.lang.RuntimeException: Unknown interpolator name: set
E/AndroidRuntime(  682):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
E/AndroidRuntime(  682):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
E/AndroidRuntime(  682):        at android.app.ActivityThread.access$1800(ActivityThread.java:112)
E/AndroidRuntime(  682):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
E/AndroidRuntime(  682):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  682):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  682):        at android.app.ActivityThread.main(ActivityThread.java:3948)
E/AndroidRuntime(  682):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  682):        at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  682):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
E/AndroidRuntime(  682):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
E/AndroidRuntime(  682):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  682): Caused by: java.lang.RuntimeException: Unknown interpolator name: set
E/AndroidRuntime(  682):        at android.view.animation.AnimationUtils.createInterpolatorFromXml(AnimationUtils.java:321)
E/AndroidRuntime(  682):        at android.view.animation.AnimationUtils.loadInterpolator(AnimationUtils.java:270)
E/AndroidRuntime(  682):        at android.view.animation.Animation.setInterpolator(Animation.java:290)
E/AndroidRuntime(  682):        at android.view.animation.Animation.<init>(Animation.java:213)
E/AndroidRuntime(  682):        at android.view.animation.TranslateAnimation.<init>(TranslateAnimation.java:54)
E/AndroidRuntime(  682):        at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:115)
E/AndroidRuntime(  682):        at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:107)
E/AndroidRuntime(  682):        at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:84)
E/AndroidRuntime(  682):        at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:64)
E/AndroidRuntime(  682):        at com.the7art.rockclock.ClockSelectActivity.onCreate(ClockSelectActivity.java:46)
E/AndroidRuntime(  682):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
E/AndroidRuntime(  682):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
E/AndroidRuntime(  682):        ... 11 more

Any idea on what causes this and how to fix? I checked some examples xml-defined animations in Android's API samples and they contain almost the same code, with different parameters, so I guess it really should work.

I see one way would be to stop defining them in xml and create animations in code, but I'd like to know if there is a way to still do it in xml :)

A: 

Found the reason.

It crashed because I had "android:interpolator="@android:anim/anticipate_overshoot_interpolator" attribute in the first anim tag. It didn't work anyway (because it needed android:shareInterpolator="false" in tag to work), so I just removed this.

I guess this is some Android 1.5 bug :)

dpimka