Android custom interpolator with xml Android custom interpolator with xml xml xml

Android custom interpolator with xml


Have a look at the error it is throwing. "customInterpolator" is not an actual interpolator. You just created that tag from nothing. You have to use the inbuilt android interpolator classes if you want to modify them. For example:

customInterpolator.xml

<accelerateInterpolator  xmlns:android="http://schemas.android.com/apk/res/android"  android:factor="2" />

Have a look at this link for different types of interpolators available in Android.

If you don't want to use one of the existing android interpolators, you can create your own programmatically.

CubicAccelerateDecelerateInterpolator.java

public class CubicAccelerateDecelerateInterpolator implements Interpolator{    @Override    public float getInterpolation(float t)    {        float x = t * 2.0f;        if (t < 0.5f)        {             return 0.5f * x * x * x;        }        x = (t - 0.5f) * 2 - 1;        return 0.5f * x * x * x + 1;    }}

As you can see, you need to create a function that returns the value of interpolation between 0 and 1 for time t. i = f(t)

Note: If you do it this way, you cannot reference this interpolator in XML. You have to create your animation programatically.