I tried making my custom interpolator after Android APIs. So this is an interpolator.
<?xml version="1.0" encoding="utf-8"?> <customInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:factor="2" />
But when I try to use it in animation:
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android"> android:fromXScale="1" android:toXScale="5" android:duration="3000" android:interpolator="@anim/custom_interpolator"/> </scale>
And nothing happens - the view is simply updated. Why is this? And why, if I try to use this, then:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="1" android:toXScale="5" android:duration="3000" android:interpolator="@anim/custom_interpolator"/> </set>
using this code:
AnimationSet animation = (AnimationSet)AnimationUtils.loadAnimation(AnimationActivity.this, R.anim.animation); animationView.startAnimation(animation);
exceptions are thrown:
java.lang.RuntimeException: Unknown interpolator name: customInterpolator at android.view.animation.AnimationUtils.createInterpolatorFromXml(AnimationUtils.java:422) at android.view.animation.AnimationUtils.loadInterpolator(AnimationUtils.java:285) at android.view.animation.Animation.setInterpolator(Animation.java:391) at android.view.animation.Animation.<init>(Animation.java:255) at android.view.animation.ScaleAnimation.<init>(ScaleAnimation.java:63) at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:119) at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:115) at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:92) at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:73) at com.example.someone.studyproject.AnimationActivity$4.onClick(AnimationActivity.java:61) at android.view.View.performClick(View.java:4633) at android.view.View$PerformClick.run(View.java:19330) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5356) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at dalvik.system.NativeStart.main(Native Method)
This is strange, I never create my custom interpolator using xml (I wanted to do this in xml just to practice it). Thanks in advance.
Now I am trying:
<scale android:fromXScale="1" android:toXScale="5" android:pivotX="50%" android:pivotY="50%" android:duration="3000"/>
and it doesnβt work - the image disappears and returns after 5 seconds. Why is this? Why does the image disappear instead of resizing?
source share